摘要:
Three types of answer: Map Solution, O(N) memory, O(N) init, O(1) pick. Like @dettier's Reservoir Sampling. O(1) init, O(1) memory, but O(N) to pick. 阅读全文
摘要:
Recursion: 是不是left子数完全由bottom往上第二层决定,如果是left子树且是叶子节点,那么就是left leaves, parent得告诉child是不是在left子树 BFS: 阅读全文
摘要:
Basic Solution: DP, O(mn) time, O(m) space, m is the size of s, n is the size of t Greedy Solution: O(n) time, O(1) space Follow Up: The best solution 阅读全文
摘要:
refer to https://discuss.leetcode.com/topic/59293/java-easiest-solution-o-logn-with-explanation Time Complexity: O(log n) update and record head in ea 阅读全文
摘要:
O(N)time, O(1) space 阅读全文
摘要:
Time Complexity: O(N) The depth of the directory/file is calculated by counting how many "\t"s are there.The time complexity is O(n) because each subs 阅读全文
摘要:
有括号这种一般要用stack, stack top 就是当前着眼的那一个NestedInteger, 可以对其添加新的元素。 注意47行判断很关键,顺带处理了 "[]," 括号后面是逗号的情况 阅读全文