Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

随笔分类 -  LintCode

1 2 3 下一页

摘要:Nothing special. Just take care of corner cases. class Solution { public: /** * @param head a ListNode * @oaram v1 an integer * @param v2 an integer * 阅读全文
posted @ 2016-04-01 13:37 Tonix 阅读(180) 评论(0) 推荐(0)

摘要:* Non-intuitive state designclass Solution {public: /** * @param A an integer array * @param k an integer * @return an integer */ ... 阅读全文
posted @ 2015-11-17 14:25 Tonix 阅读(734) 评论(0) 推荐(0)

摘要: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... 阅读全文
posted @ 2015-11-16 03:45 Tonix 阅读(274) 评论(0) 推荐(0)

摘要:https://codesolutiony.wordpress.com/2015/05/24/lintcode-coins-in-a-line-iii/A very juicy one! Deserve more consideration.class Solution {public: /*... 阅读全文
posted @ 2015-11-15 13:25 Tonix 阅读(301) 评论(0) 推荐(0)

摘要:Nice one to learn: DP + Game Theoryhttps://lefttree.gitbooks.io/leetcode/content/dynamicProgramming2/coinsInLine2.htmlIn game theory, we assume the ot... 阅读全文
posted @ 2015-11-09 12:57 Tonix 阅读(213) 评论(0) 推荐(0)

摘要: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... 阅读全文
posted @ 2015-11-06 15:50 Tonix 阅读(266) 评论(0) 推荐(0)

摘要:Simply a variation to "Permutation Index". When calculating current digit index, we consider duplicated case.Again, similar as "Digit Counts", it is a... 阅读全文
posted @ 2015-11-04 08:56 Tonix 阅读(304) 评论(0) 推荐(0)

摘要:Lesson learnt: one effective solution for bit\digit counting problems: counting by digit\bithttp://www.hawstein.com/posts/20.4.htmlclass Solution {pub... 阅读全文
posted @ 2015-11-04 07:31 Tonix 阅读(226) 评论(0) 推荐(0)

摘要:Great great DP learning experience:http://www.cnblogs.com/yuzhangcmu/p/4279676.htmlRemember 2 steps of DP: a) setup state transfer equation; b) setup ... 阅读全文
posted @ 2015-10-30 01:22 Tonix 阅读(184) 评论(0) 推荐(0)

摘要:Based on Bucketing and "Majority Number I".class Solution { pair majorityNumber0(vector &num) { int count = 0; int ret = 0; fo... 阅读全文
posted @ 2015-10-28 06:10 Tonix 阅读(203) 评论(0) 推荐(0)

摘要: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... 阅读全文
posted @ 2015-10-28 05:25 Tonix 阅读(170) 评论(0) 推荐(0)

摘要: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... 阅读全文
posted @ 2015-10-28 04:27 Tonix 阅读(179) 评论(0) 推荐(0)

摘要:4 Pointer solution. Key: when moving pointers, we skip duplicated ones.Ref: https://github.com/xbz/lintcode/blob/master/4_sum/4sum.cppclass Solution {... 阅读全文
posted @ 2015-10-24 09:17 Tonix 阅读(152) 评论(0) 推荐(0)

摘要: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... 阅读全文
posted @ 2015-10-22 13:15 Tonix 阅读(222) 评论(0) 推荐(0)

摘要:New stuff learnt - Union-Find. Simpler and more elegant than I thought.class Solution { unordered_map father; int find(int val) { if(!... 阅读全文
posted @ 2015-10-21 13:09 Tonix 阅读(198) 评论(0) 推荐(0)

摘要:Should be "Medium" or even "Easy".. Just with a little Greedy.class Solution {public: /** * @param S: A list of integers * @return: An inte... 阅读全文
posted @ 2015-10-21 07:53 Tonix 阅读(261) 评论(0) 推荐(0)

摘要: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;... 阅读全文
posted @ 2015-10-20 14:40 Tonix 阅读(197) 评论(0) 推荐(0)

摘要:Lesson learnt: for any calculator problems, keep 2 stacks: 1 for operators and 1 for operands.class Solution { stack op; stack data; void... 阅读全文
posted @ 2015-10-19 14:28 Tonix 阅读(184) 评论(0) 推荐(0)

摘要: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... 阅读全文
posted @ 2015-10-19 04:37 Tonix 阅读(133) 评论(0) 推荐(0)

摘要: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... 阅读全文
posted @ 2015-10-18 12:57 Tonix 阅读(153) 评论(0) 推荐(0)

1 2 3 下一页