摘要:
Lexicographicallyalgorithms:1. Iterate array from back to front, and find the first decreasing point: 1,2,4,3 -- 42. Iterate array from back to front,... 阅读全文
摘要:
Greedy, Greedy, Greedy.. It is all about maximum interval update.One trick is, we start looping over each element from the one nearest to end to farth... 阅读全文
摘要:
A simulation problem. We simple walk through all reachable items until we cannot proceed.class Solution {public: bool canJump(int A[], int n) { ... 阅读全文
摘要:
Next time you see a numeric problem has a too straightforward solution, think about optimized one.Like this one: recursion\iteration is tooo slow. SoD... 阅读全文
摘要:
I fell in a deadloop, and didn't see the actual recursion pattern.Reference:http://fisherlei.blogspot.com/2013/03/leetcode-unique-binary-search-trees-... 阅读全文
摘要:
A very interesting numeric problem. It involves a lot tricks.Linear search (by +\-) is not feasible - too slow. So binary search is a good idea. Also ... 阅读全文
摘要:
Similar with "Longest Consecutive Sequence". Another usage to hashset.Take care of corner cases!class Solution {public: int firstMissingPositive(in... 阅读全文
摘要:
Similar with "Climb stairs" but with more restrictions.// Ref: http://yucoding.blogspot.com/2013/01/leetcode-question-26-decode-ways.htmlclass Solu... 阅读全文
摘要:
Typical recurrsion\DFS problem. Just take care of memory use.class Solution {public: vector> ret; void go(int currMaxN, int currK, int k, unorde... 阅读全文
摘要:
Compared with I version, the tree could be incomplete. The only difference is that, we connect current node's child to next non-childrenless' node's f... 阅读全文
摘要:
Flood-Fill. BFS. But there's a trick. If we fill surrounded region directly, extra bookkeeping cost is needed - because we don't know whether that reg... 阅读全文
摘要:
Comparison-based sorting takes O(nlgn), so hashset is a good idea. After keeping records of all numbers in the hashset, you start checking each number... 阅读全文
摘要:
Nothing to hard to think. Just take care of boundary conditions.class Solution {public: string convert(string s, int nRows) { if(s.empty() |... 阅读全文