LeetCode 200. Number of Islands

https://leetcode.com/problems/number-of-islands/description/ DFS of a map, O(N^2)

 

LeetCode 23. Merge k Sorted Lists

https://leetcode.com/problems/merge-k-sorted-lists/description/ Use max heap, the time complexity is O( log(k) * N )

 

LeetCode 222. Count Complete Tree Nodes

https://leetcode.com/problems/count-complete-tree-nodes/description/ 简单的二分法分治,探测(子)树的左右侧是否相等即可。 (下面代码没实现)想要更快的话,其实自从第一次算出左侧的深度后,后面的左测深度直接可以通过减法求出,不用再去探测一次了。

 

No core will be dumped when calling exit() in a signal handler

The customized abnormal signal handler (e.g. SIGSEGV handler) will function abnormally if we call exit() inside the handler: the program will exit “as normal” however it did had some severe memory issue. See code snippet below, try to run with / without “X” argument.

Output:

   

LeetCode 76. Minimum Window Substring

76. Minimum Window Substring 思路: 构造一个哈希表结构统计我们的需求,也就是字符串t中每个字符的数量,方便起见如果有需求则哈希表的对应值-1。另外存储一下当前解的起始位置START以及最优解的位置。 扫描字符串s,在位置s[i]时如果能够满足需求(即哈希表中没有负值),则从START开始清除无用的字符直至无法满足需求位置。比如需求是A:1, B:2,START开始的字符是DEFBAB,则清除DEF。清除完成后更新START值并跟当前已知的最优解比较,更新最优解。 啰嗦一句,似乎相当一部分substring类型的题目都能用hash table + two pointers的方式解决。