摘要:Taking advantage of 'sparse'class Solution {public: vector> multiply(vector>& A, vector>& B) { vector> ret; int ha = A.si...
阅读全文
11 2015 档案
摘要:Simple data structure but not that easy to figure out.. MHT -> balanced tree.https://leetcode.com/problems/minimum-height-trees/Lesson learnt: Focus o...
阅读全文
摘要:A sly knapsack problem in disguise! Thanks tohttps://github.com/bhajunsingh/programming-challanges/tree/master/hackerrank/algorithms/the-indian-jobLes...
阅读全文
摘要:I had the same BFS idea as one of the AC code this: because dying pattern is spead from the initial dying ones :)#include #include #include using name...
阅读全文
摘要:Learnt from here:http://www.cnblogs.com/lautsie/p/3798165.htmlIdea is: we union all pure black edges so we get 1+ pure black edge groups. Then we can ...
阅读全文
摘要:Very good DP one.First I figured out a O(n^2) solution:class Solution {public: int maxProfit(vector& prices) { int n = prices.si...
阅读全文
摘要:[Concepts]Consistent Hashing: instead of MOD, hash() to certain point within 0-2^31. Range based[Logistics\Glue]Zookeeper: locking\service finder\lead...
阅读全文
摘要:Actually I think problem statement is somewhat misleading. No need to mention range [L, R] at all.The intention is a variation to "Largest Rectangle" ...
阅读全文
摘要:2D Segment Tree -> Quad Tree. class Node // 2D Segment Tree { public: Node(vector> &m, int ix0, int iy0, int ix1, int iy1) ...
阅读全文
摘要:The most interesting, flexible and juicy binary tree problem I have ever seen.I learnt it from here: https://codepair.hackerrank.com/paper/5fIoGg74?b=...
阅读全文
摘要:XOR -> 0 is the key (make it even pair): http://www.cnblogs.com/lautsie/p/3908006.htmlSomething to learn about basic Game Theory: http://www.cdf.toron...
阅读全文
摘要:A typical game theory problem - Recursion + Memorized Searchhttp://justprogrammng.blogspot.com/2012/06/interviewstreet-challenges-permutation.html#.Vl...
阅读全文
摘要:Same as LintCode "Sliding Window Median", but requires more care on details - no trailing zeroes.#include #include #include #include #include #include...
阅读全文
摘要:Something to learn: Rotation ops in AVL tree does not require recursion.https://github.com/andreimaximov/hacker-rank/blob/master/data-structures/tree/...
阅读全文
摘要:Something to learn:http://blog.csdn.net/yuwenshi/article/details/36666453Shortest Job First Algorithm - kinda greedy: we do shorter job first BUT we o...
阅读全文
摘要:Regular Union-Find practice one.#include #include #include #include #include #include #include #include #include using namespace std;unordered_map ps;...
阅读全文
摘要:Fenwick tree can do this job.class NumArray { vector in; vector ft; int query(int i) { i += 1; i = min(i, int(ft.size() - 1...
阅读全文
摘要:A natural DFS thought. Several pruning tricks can be applied. Please take care of date type(long long).class Solution { bool _check(string a, strin...
阅读全文
摘要:* Non-intuitive state designclass Solution {public: /** * @param A an integer array * @param k an integer * @return an integer */ ...
阅读全文
摘要:DFS + Memorized Search (DP)class Solution { int dfs(int i, int j, int row, int col, vector>& A, vector>& dp) { if(dp[i][j] != 0) retu...
阅读全文
摘要:https://codesolutiony.wordpress.com/2015/05/24/lintcode-coins-in-a-line-iii/A very juicy one! Deserve more consideration.class Solution {public: /*...
阅读全文
摘要:Yes the accu* is not necessary :)class NumMatrix { vector> dp;public: NumMatrix(vector> &matrix) { int h = matrix.size(); if(!h) ret...
阅读全文
摘要:Here is the thought flow: we are trying 'find' the boundary - it is a search, so binary search.class Solution { bool isRowHit(vector>& image, int r) ...
阅读全文
摘要:Nice one to learn: DP + Game Theoryhttps://lefttree.gitbooks.io/leetcode/content/dynamicProgramming2/coinsInLine2.htmlIn game theory, we assume the ot...
阅读全文
摘要:1AC! Yes! Intuitive thought will be: we walk from up-left to down-right - but we should only walk along the 'lowest edge' in the sorted matrix - so it...
阅读全文
摘要:DFS with pruning. The thought flow: for each char, we have 2 choices: pick or not - then DFS.class Solution { int len; unordered_set rec; vector ...
阅读全文
摘要:Simply a variation to "Permutation Index". When calculating current digit index, we consider duplicated case.Again, similar as "Digit Counts", it is a...
阅读全文
摘要:Lesson learnt: one effective solution for bit\digit counting problems: counting by digit\bithttp://www.hawstein.com/posts/20.4.htmlclass Solution {pub...
阅读全文

浙公网安备 33010602011771号