摘要:Nothing special. Just take care of corner cases. class Solution { public: /** * @param head a ListNode * @oaram v1 an integer * @param v2 an integer *
阅读全文
随笔分类 - LintCode
摘要:* 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: /*...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要:Great great DP learning experience:http://www.cnblogs.com/yuzhangcmu/p/4279676.htmlRemember 2 steps of DP: a) setup state transfer equation; b) setup ...
阅读全文
摘要:Based on Bucketing and "Majority Number I".class Solution { pair majorityNumber0(vector &num) { int count = 0; int ret = 0; fo...
阅读全文
摘要:A reverse version of the Dictionary algorithm :) If you AC-ed "Next Permutation II", copy it over and just reverse the conditions.class Solution {publ...
阅读全文
摘要:Such a classic DP.. Thought flow:1. find out the 2 vars in the problem statement: n and k2. setup dp equation - my first thought was by n which was no...
阅读全文
摘要:4 Pointer solution. Key: when moving pointers, we skip duplicated ones.Ref: https://github.com/xbz/lintcode/blob/master/4_sum/4sum.cppclass Solution {...
阅读全文
摘要:A typical Union-Find one. I'm using a kinda Union-Find solution here. Some boiler-plate code - yeah I know.class Solution { unordered_set hs; // st...
阅读全文
摘要:New stuff learnt - Union-Find. Simpler and more elegant than I thought.class Solution { unordered_map father; int find(int val) { if(!...
阅读全文
摘要:Should be "Medium" or even "Easy".. Just with a little Greedy.class Solution {public: /** * @param S: A list of integers * @return: An inte...
阅读全文
摘要:Regular segment tree usage. Should be medium though.struct Node{ Node(int rs, int re) : s(rs), e(re), left(nullptr), right(nullptr){} int s;...
阅读全文
摘要:Lesson learnt: for any calculator problems, keep 2 stacks: 1 for operators and 1 for operands.class Solution { stack op; stack data; void...
阅读全文
摘要:Sliding window doesn't work. So it is a typical partial_sum base solution. As below. However if you use a balanced binary search tree, you can get O(n...
阅读全文
摘要:A variantion to "largest\smallest consecutive subarray". Idea is, at position i, the current max diff is max(max_left[i] - min_right[i+1], max_right[i...
阅读全文

浙公网安备 33010602011771号