摘要:
Lesson learnt: Get rid of XX algorithm routines clogging your mind and focus\enjoy the problem itself!// Forward declaration of the knows API.bool kno... 阅读全文
摘要:
sum[i..j] = sum[0..j] - sum[0..i-1]. We use a hashmap to check a previous matching index with a given number.class Solution {public: vector subarra... 阅读全文
摘要:
Sorting is a natural solution. But, you don't have to run O(nlgn) sorting for all the time. Counting sort is O(n)!class Solution {public: int hInde... 阅读全文
摘要:
I made it too complicated first.. It is really simply if full-tree in-order traversal is allowed.class Solution { int inx, sofar; // closest boo... 阅读全文
摘要:
A variation to a classical DP: LCS.class Solution {public: /** * @param A an integer array * @return A list of integers includes the index o... 阅读全文
摘要:
It can be solved based on the code from "Strobogrammatic Number II". The idea is pretty straight forward - binary search the boundaries.class Solution... 阅读全文
摘要:
This is abouthttps://en.wikipedia.org/wiki/Run-length_encoding. The trick is, for a valid char, we only compress up to 254 occurences - count 255 mean... 阅读全文
摘要:
Key: each of 2\3\5 is trying to multiply with the least number it has not been multiplied.class Solution {public: int nthUglyNumber(int n) { ... 阅读全文
摘要:
Another topological sorting problem. Note: the DFS one is like a 'post-order' traversal.class Solution { unordered_map> g; unordered_set visited... 阅读全文
摘要:
Use constructive strategy: we compose each of the 26 variations of one word.class Solution {public: vector> groupStrings(vector& strings) { ... 阅读全文
摘要:
Classic DP! For house[i] to pick a min-color from dp[i-1], we only need to check if color j is the min cost color index of dp[i - 1]; if yes, then we ... 阅读全文