Not hard to think of a solution. But the key is all details.class Solution {public: /** *@param n: Given a decimal number that is passed in as ...
分类:
其他好文 时间:
2015-10-04 12:20:18
阅读次数:
257
Recursion + Memorized Search(DP). And apparently, the code below can be iterative with only 3 vars - DP.class Solution { unordered_map cache;public...
分类:
其他好文 时间:
2015-10-03 13:12:54
阅读次数:
169
LeetCode AC code failed last case with TLE. We need further pruning - we only enumerate all possible lengths of all dict words.class Solution { vec...
分类:
其他好文 时间:
2015-10-03 07:20:37
阅读次数:
191
Something new I learnt from it: what is Treap and a O(n) constructionhttps://en.wikipedia.org/wiki/Cartesian_tree#Efficient_constructionclass Solution...
分类:
其他好文 时间:
2015-10-03 07:19:15
阅读次数:
314
Flip over your mind: in rotated subarray case, we can simply cut the continuous smallest subarray.class Solution {public: /** * @param A an int...
分类:
其他好文 时间:
2015-10-02 01:26:38
阅读次数:
248
Partition and swapping. A lot details to take care.class Solution {public: /** * @param A: An integer array. * @return: void */ void...
分类:
其他好文 时间:
2015-10-01 16:30:24
阅读次数:
157
Fenwick Tree is perfect for this problem, though space complexity is not quite efficient.class Solution { ////////////////// // Fenwick Tree // ...
分类:
其他好文 时间:
2015-10-01 11:32:57
阅读次数:
147
Here is a BFS solution which is compatible with LeetCode binary tree format.class Solution {public: /** * This method will be invoked first, yo...
分类:
其他好文 时间:
2015-09-30 14:28:54
阅读次数:
176
DFS ended up with TLE. Only BFS works./** * Definition for Directed graph. * struct DirectedGraphNode { * int label; * vector neighbors; * ...
分类:
其他好文 时间:
2015-09-24 07:04:31
阅读次数:
188
Naive solution is O(n^4). But on 1 certain dimension, naive O(n^2) can be O(n) by this well-known equation: sum[i..j] = sum[0..j] - sum[0..i]. And pls...
分类:
其他好文 时间:
2015-09-23 06:47:14
阅读次数:
224