Tony's Log

Algorithms, Distributed System, Machine Learning

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

2014年8月21日

摘要: First I thought of a DP solution.. but TLE. So there must be a O(n). I thought of Mono-Queue.. but looks too complex.So what is the naive solution? O(... 阅读全文
posted @ 2014-08-21 13:23 Tonix 阅读(172) 评论(0) 推荐(0)

摘要: 1A! We get median of each array and compare them, then we know which half should be disguarded and how many should be disguarded.class Solution {publi... 阅读全文
posted @ 2014-08-21 12:09 Tonix 阅读(162) 评论(0) 推荐(0)

摘要: A classic and representative DP problem. To be revised later. Quite a few interesting details to think about.class Solution {public: int numDistinc... 阅读全文
posted @ 2014-08-21 11:28 Tonix 阅读(138) 评论(0) 推荐(0)

2014年8月19日

摘要: 1A! This is actually a basic question in Combinatorics: if at digit[k] = n, it contributes (k-1)! * n to the targeted index.class Solution {public: ... 阅读全文
posted @ 2014-08-19 13:26 Tonix 阅读(148) 评论(0) 推荐(0)

摘要: 找到自己切题的主要障碍了:试图刚读完题就foresee到最后的solution,其实就是妄图利用比较省事的感性直接超越逻辑推导的理性:其实就是懒。超验感性实际上是建立在大量理性的思考与实践上的。这话不是我说的,出自一位顶尖数学家之口。更别说偶了。 阅读全文
posted @ 2014-08-19 12:40 Tonix 阅读(149) 评论(0) 推荐(0)

摘要: Nothing but admire: http://fisherlei.blogspot.com/2013/11/leetcode-linked-list-cycle-ii-solution.htmlclass Solution {public: ListNode *detectCycle(... 阅读全文
posted @ 2014-08-19 12:36 Tonix 阅读(143) 评论(0) 推荐(0)

摘要: Refer: http://blog.unieagle.net/2012/12/05/leetcode%E9%A2%98%E7%9B%AE%EF%BC%9Abest-time-to-buy-and-sell-stock-iii%EF%BC%8C%E4%B8%80%E7%BB%B4%E5%8A%A8%... 阅读全文
posted @ 2014-08-19 11:42 Tonix 阅读(178) 评论(0) 推荐(0)

2014年8月18日

摘要: Similar strategy could be applied to 4Sum, as 2sum to 3sum, but that'll be O(n^3). Instead of 3 + 1, we can also divide it into 2 + 2. So the problem ... 阅读全文
posted @ 2014-08-18 12:23 Tonix 阅读(187) 评论(0) 推荐(0)

摘要: Simply a variation of 3Sum:class Solution {public: int threeSumClosest(vector &num, int target) { int ret = 99999999999; std::sort(nu... 阅读全文
posted @ 2014-08-18 10:39 Tonix 阅读(138) 评论(0) 推荐(0)

摘要: Now that you've solved 2sum, 3sum can be easily converted as 2sum.Also please note the while loops for i1 and i2: they are to make sure no duplicates.... 阅读全文
posted @ 2014-08-18 10:12 Tonix 阅读(151) 评论(0) 推荐(0)

2014年8月16日

摘要: O(n^2) is a naive solution. As rule of thumb, there must be O(n) soluion. Yes - Greedy.We assume widest container contains the most water, greedily, b... 阅读全文
posted @ 2014-08-16 14:38 Tonix 阅读(139) 评论(0) 推荐(0)

摘要: -!5. Trie\Suffix Tree:http://blog.csdn.net/v_july_v/article/details/6897097 Trie: think about how you used King Dict by typing; Suffix Tree: all suff... 阅读全文
posted @ 2014-08-16 14:06 Tonix 阅读(213) 评论(0) 推荐(0)

摘要: Simply DFS + Backtrace, as N-Queenclass Solution {public: vector> rows; vector> cols; vector>> subboxHm; bool isValid(char c, int i, int j... 阅读全文
posted @ 2014-08-16 06:34 Tonix 阅读(142) 评论(0) 推荐(0)

2014年8月15日

摘要: Here another memory for speed implementation:class Solution {public: bool isValidSudoku(vector > &board) { size_t row_cnt = board.size(); ... 阅读全文
posted @ 2014-08-15 12:20 Tonix 阅读(151) 评论(0) 推荐(0)

摘要: Main reference: http://zhaohongze.com/wordpress/2013/12/10/leetcode-candy/I was confused by the constraint on BOTH sides of an element. Strategy is: s... 阅读全文
posted @ 2014-08-15 10:13 Tonix 阅读(247) 评论(0) 推荐(0)

摘要: http://yucoding.blogspot.com/2012/12/leetcode-question-13-binary-tree.htmlUsually for tree problems, it is either recursion or traversal. For this one... 阅读全文
posted @ 2014-08-15 08:11 Tonix 阅读(114) 评论(0) 推荐(0)

摘要: I got a DP solution first which is O(n^2). Apparently it is not a optimized one - think about: it is linear value space. There must be O(n) solution.A... 阅读全文
posted @ 2014-08-15 04:48 Tonix 阅读(310) 评论(0) 推荐(0)

2014年8月14日

摘要: 1A. It is a design problem actually. It tests your ability to connect your knowledge of data structures & algorithms, with real world problems.class L... 阅读全文
posted @ 2014-08-14 08:46 Tonix 阅读(167) 评论(0) 推荐(0)

2014年8月13日

摘要: Just take care of corner cases!class Solution {public: vector fullJustify(vector &words, int L) { vector ret; int startInx = 0; ... 阅读全文
posted @ 2014-08-13 09:40 Tonix 阅读(143) 评论(0) 推荐(0)

摘要: It is not as easy as I thought it to be, mostly because of time\space limitation. And actually that's the punch line of this problemMy intuition was D... 阅读全文
posted @ 2014-08-13 07:30 Tonix 阅读(160) 评论(0) 推荐(0)