using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Microsoft.Coyote.Tasks; | |
namespace TinyService | |
{ | |
using Document = Dictionary<string, string>; | |
using Collection = Dictionary<string, Dictionary<string, string>>; |
Nocturne in B-flat minor Op. 9 No. 1
Nocturnes, Op. 9: No. 2 in E-flat major
Andante spianato in G Major, Op. 22
Nocturne in B major Op. 32 No. 1
Nocturne in D-flat major Op. 27 No. 2
Nocturne in E-flat major Op. 9 No. 2
Nocturne in E minor Op. 72 No. 1
Nocturne in F# minor Op. 15 No. 2
Prelude in E minor, Op. 28 No. 4
/** | |
* Prefix sums of nums, preSum[i] = sum of range [0, j) | |
* sum[i, j) = preSum[j] - preSum[i] | |
* | |
* @param nums | |
* @return preSum array | |
*/ | |
public static int[] getPrefixSum(int[] nums) { | |
int[] preSum = new int[nums.length + 1]; | |
for (int i = 1; i <= nums.length; i++) { |
["this","summer","thomas","get","actually","actually","rich","and","possess","the","actually","great","and","fine","vehicle","every","morning","he","drives","one","nice","car","around","one","great","city","to","have","single","super","excellent","super","as","his","brunch","but","he","only","eat","single","few","fine","food","as","some","fruits","he","wants","to","eat","an","unique","and","actually","healthy","life"] ["this","summer","thomas","get","very","very","rich","and","possess","the","very","fine","and","well","car","every","morning","he","drives","a","fine","car","around","unique","great","city","to","take","any","really","wonderful","fruits","as","his","breakfast","but","he","only","drink","an","few","excellent","breakfast","as","a","super","he","wants","to","drink","the","some","and","extremely","healthy","life"] [["good","nice"],["good","excellent"],["good","well"],["good","great"],["fine","nice"],["fine","excellent"],["fine","well"],["fine","great"],["wonderful","nice"]
- Encode String with Shortest Length
Given a non-empty string, encode the string such that its encoded length is the shortest.
The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times.
Note:
k will be a positive integer and encoded string will not be empty or have extra space. You may assume that the input string contains only lowercase English letters. The string's length is at most 160.
int[] arr = {5, 3, 5, 7, 8, 9, 9, 10};
int[] res = new int[2]; //res[0] sum of even idx elems in arr, res[1] sum of odd idx elems
...
// normal way
if (i % 2 == 0) {
res[0] += arr[i];
} else {
res[1] += arr[i];
}
// Check leap year | |
public boolean isLeapYear(int year) { | |
boolean leapYear = false; | |
if (year % 4 == 0) { | |
if (year % 100 == 0) { | |
if ( year % 400 == 0) { | |
leapYear = true; | |
} | |
} else { | |
leapYear = true; |
public int binarySearch(int[] arr, int target) { | |
int l = 0, r = arr.length; | |
while (l < r) { | |
int m = l + (r - l) / 2; | |
if (arr[m] == target) return m; | |
else if (arr[m] > target) { | |
r = m; | |
} | |
else { | |
l = m + 1; |