Tony's Log

Algorithms, Distributed System, Machine Learning

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

2015年10月12日

摘要: O(nlgn) - my first thought is, keep maintaining a balanced binary search tree, and then use "Binary Search Tree Closest" one to solve it. But unfortun... 阅读全文
posted @ 2015-10-12 02:32 Tonix 阅读(162) 评论(0) 推荐(0)

2015年10月10日

摘要: Here is the mind flow: we don't know 1st token right? then we try it one by one - recursively.typedef unordered_map HMap;class Solution { bool go(s... 阅读全文
posted @ 2015-10-10 14:42 Tonix 阅读(191) 评论(0) 推荐(0)

摘要: 2D DP. DP is all about choices - current choice with previous choice :) A natural solution as below, and of course we can simply use rolling array for... 阅读全文
posted @ 2015-10-10 07:34 Tonix 阅读(163) 评论(0) 推荐(0)

2015年10月9日

摘要: My first try was, using partial sort to figure out numbers layer by layer in the heap.. it only failed with TLE with the last test case. The problem i... 阅读全文
posted @ 2015-10-09 01:50 Tonix 阅读(222) 评论(0) 推荐(0)

2015年10月7日

摘要: Classic DP. The initial intuitive O(k*n^2) solution is like this: class Solution { public: /** * @param pages: a vector of integers * @param k: an int 阅读全文
posted @ 2015-10-07 15:12 Tonix 阅读(870) 评论(0) 推荐(0)

摘要: Bucketing! A lot of details to take care.struct Bucket{ Bucket() :l(-1), r(-1), bValid(false){};int l, r; bool bValid;};class Solution {public: ... 阅读全文
posted @ 2015-10-07 13:50 Tonix 阅读(177) 评论(0) 推荐(0)

摘要: Binary search. Please not data types and some details.class Solution {public: /** *@param L: Given n pieces of wood with length L[i] *@para... 阅读全文
posted @ 2015-10-07 11:47 Tonix 阅读(229) 评论(0) 推荐(0)

2015年10月6日

摘要: This is sth. for me to learn..https://github.com/kamyu104/LintCode/blob/master/C++/expression-evaluation.cpp 阅读全文
posted @ 2015-10-06 15:08 Tonix 阅读(150) 评论(0) 推荐(0)

摘要: Idea is the same: climbing up the hill along one edge (Greedy)! Visualize it in your mind!class Solution {public: /** * @param A: An integer ma... 阅读全文
posted @ 2015-10-06 07:45 Tonix 阅读(164) 评论(0) 推荐(0)

2015年10月5日

摘要: Not hard to find a solution, but there are several corner cases.class Solution {public: /** * @param root: The root of the binary search tree. ... 阅读全文
posted @ 2015-10-05 06:35 Tonix 阅读(189) 评论(0) 推荐(0)

摘要: Greedy: remove earliest down-edge: like "54", "97".class Solution {public: /** *@param A: A positive integer which has N digits, A is a string.... 阅读全文
posted @ 2015-10-05 01:14 Tonix 阅读(163) 评论(0) 推荐(0)

2015年10月4日

摘要: Not hard to think of a solution. But the key is all details.class Solution {public: /** *@param n: Given a decimal number that is passed in as ... 阅读全文
posted @ 2015-10-04 11:54 Tonix 阅读(158) 评论(0) 推荐(0)

摘要: A coding practice.class Solution {public: // encoding: 2 - 1 to 0; -1 - 0 to live void gameOfLife(vector>& board) { int h = board.size();... 阅读全文
posted @ 2015-10-04 10:31 Tonix 阅读(182) 评论(0) 推荐(0)

2015年10月3日

摘要: Recursion + Memorized Search(DP). And apparently, the code below can be iterative with only 3 vars - DP.class Solution { unordered_map cache;public... 阅读全文
posted @ 2015-10-03 12:34 Tonix 阅读(138) 评论(0) 推荐(0)

摘要: LeetCode AC code failed last case with TLE. We need further pruning - we only enumerate all possible lengths of all dict words.class Solution { vec... 阅读全文
posted @ 2015-10-03 07:02 Tonix 阅读(215) 评论(0) 推荐(0)

摘要: Something new I learnt from it: what is Treap and a O(n) constructionhttps://en.wikipedia.org/wiki/Cartesian_tree#Efficient_constructionclass Solution... 阅读全文
posted @ 2015-10-03 06:23 Tonix 阅读(183) 评论(0) 推荐(0)

2015年10月2日

摘要: Binary search.class Solution { int _findClosest(vector &A, int v) { int s = 0, e = A.size() - 1; int ret = INT_MAX; while(s... 阅读全文
posted @ 2015-10-02 13:02 Tonix 阅读(275) 评论(0) 推荐(0)

摘要: Flip over your mind: in rotated subarray case, we can simply cut the continuous smallest subarray.class Solution {public: /** * @param A an int... 阅读全文
posted @ 2015-10-02 00:19 Tonix 阅读(155) 评论(0) 推荐(0)

2015年10月1日

摘要: Partition and swapping. A lot details to take care.class Solution {public: /** * @param A: An integer array. * @return: void */ void... 阅读全文
posted @ 2015-10-01 15:27 Tonix 阅读(165) 评论(0) 推荐(0)

摘要: Fenwick Tree is perfect for this problem, though space complexity is not quite efficient.class Solution { ////////////////// // Fenwick Tree // ... 阅读全文
posted @ 2015-10-01 11:14 Tonix 阅读(203) 评论(0) 推荐(0)

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