摘要:
Use buckets to record the last position of digit 0 ~ 9 in this num. Loop through the num array from left to right. For each position, we check whether 阅读全文
摘要:
The sample input is very confusing when time t has mixed meaning of beginning of time t for start and end of time t for end We can increase all end ti 阅读全文
摘要:
注意这道题:Must be exactly one distance apart. Not the same. 另外FB面经有一道比较狠的这个题的变形: 这题就是one edit distance的变形题,难点在于给的Iterator,事先不知道两个file的长度,也不允许用extra space( 阅读全文
摘要:
小心这里是index triplets, 不是nums[i]数组元素的triplets, 所以3Sum那道题里面的跳过条件不用了 因为不关心每个index具体是什么,只关心个数,所以可以排序 阅读全文
摘要:
Time Complexity will be O(n) because the "start" and "end" points will only move from left to right once. 阅读全文
摘要:
我又想到了另一个idea,使用那个assumption可以达到O(1) 复杂度:首先判断isUp or not,仅以isUp为例, 假设A[x] 是最高点,则有:A[x] - A[i] = x - i. A[x] - A[j] = j - x由此可以解出 x = 1/ 2 * (A[j] - A[i 阅读全文