Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 25 下一页

2015年10月30日

摘要: 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 阅读(182) 评论(0) 推荐(0)

2015年10月28日

摘要: A simple application to binary tree traversal.class Solution { typedef pair Rec; // last val - length unsigned ret; void go(TreeNode *p, Rec ... 阅读全文
posted @ 2015-10-28 11:47 Tonix 阅读(164) 评论(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 阅读(199) 评论(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 阅读(167) 评论(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 阅读(174) 评论(0) 推荐(0)

2015年10月24日

摘要: 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 阅读(150) 评论(0) 推荐(0)

2015年10月23日

摘要: Interesting one.. I can feel sparkle in mind in the proposed solution - just pick the mid-point! (yes some boiler-plate code below)class Solution { ... 阅读全文
posted @ 2015-10-23 13:19 Tonix 阅读(191) 评论(0) 推荐(0)

2015年10月22日

摘要: 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 阅读(220) 评论(0) 推荐(0)

2015年10月21日

摘要: 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 阅读(197) 评论(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 阅读(258) 评论(0) 推荐(0)

2015年10月20日

摘要: 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 阅读(195) 评论(0) 推荐(0)

摘要: Similar one as LintCode "Data Stream Median".class MedianFinder { priority_queue hl; // max-heap priority_queue, std::greater > hr; // min-heapp... 阅读全文
posted @ 2015-10-20 14:05 Tonix 阅读(154) 评论(0) 推荐(0)

2015年10月19日

摘要: 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 阅读(181) 评论(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 阅读(129) 评论(0) 推荐(0)

2015年10月18日

摘要: 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 阅读(151) 评论(0) 推荐(0)

2015年10月16日

摘要: A natural recursion thought.. Please note we can cache intermediate results. class Solution { unordered_map<string, bool> hs; public: bool canWin(stri 阅读全文
posted @ 2015-10-16 11:23 Tonix 阅读(151) 评论(0) 推荐(0)

2015年10月15日

摘要: Besides heap, multiset can also be used:class Solution { void removeOnly1(multiset &ms, int v) { auto pr = ms.equal_range(v); ms.e... 阅读全文
posted @ 2015-10-15 14:37 Tonix 阅读(138) 评论(0) 推荐(0)

2015年10月14日

摘要: Recursive counting..class Solution { long long w(int n) { long long ret = 1; while(n > 1) { ret *= n; ... 阅读全文
posted @ 2015-10-14 06:55 Tonix 阅读(241) 评论(0) 推荐(0)

2015年10月13日

摘要: Warning: input could be > 10000...Solution by segment tree:struct Node{ Node(int s, int e) : start(s), end(e), cnt(0), left(nullptr), right(nullptr... 阅读全文
posted @ 2015-10-13 13:57 Tonix 阅读(155) 评论(0) 推荐(0)

摘要: Same as LintCode 'Coins in a line'. Here is mind-flow: 4 is a definite lose, for (4 + 1), (4 + 2), (4 + 3), we can put the other player into slot 4 - ... 阅读全文
posted @ 2015-10-13 05:34 Tonix 阅读(183) 评论(0) 推荐(0)

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 25 下一页