Tony's Log

Algorithms, Distributed System, Machine Learning

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

2014年8月12日

摘要: Main reference:http://zhaohongze.com/wordpress/2014/01/04/leetcode-minimum-window-substring/The ART of counting. So difficult and beautiful problem. I... 阅读全文
posted @ 2014-08-12 11:12 Tonix 阅读(167) 评论(0) 推荐(0)

摘要: It took me numerous submissions to get AC.... until I checked this article:http://leetcode.com/2011/09/regular-expression-matching.htmlVery clean idea... 阅读全文
posted @ 2014-08-12 05:05 Tonix 阅读(150) 评论(0) 推荐(0)

2014年8月11日

摘要: Problem is, find all values that share the same key value. Similar as another LeetCode problem, hashmap is a good choice.http://yucoding.blogspot.com/... 阅读全文
posted @ 2014-08-11 12:56 Tonix 阅读(162) 评论(0) 推荐(0)

摘要: I briefly took a look at:http://yucoding.blogspot.com/2013/01/leetcode-question-27-interleaving-string.htmlAnd I got 1A :)This is the best problem to ... 阅读全文
posted @ 2014-08-11 11:57 Tonix 阅读(157) 评论(0) 推荐(0)

2014年8月10日

摘要: A so juicy and interesting problem! Recommend to everyone!A final solution may not jump into your mind immediately, of course, DP is not a trivial top... 阅读全文
posted @ 2014-08-10 14:05 Tonix 阅读(305) 评论(0) 推荐(0)

2014年8月9日

摘要: What a juicy problem to solve :) My intuition is DP, but failed with TLE. Then I referred to:http://leetcode.com/2011/05/longest-substring-without-rep... 阅读全文
posted @ 2014-08-09 06:42 Tonix 阅读(138) 评论(0) 推荐(0)

摘要: Here is the most elegant code I've seen to this problem:http://yucoding.blogspot.com/2013/02/leetcode-question-123-wildcard-matching.htmlSimply wow. I... 阅读全文
posted @ 2014-08-09 04:02 Tonix 阅读(210) 评论(0) 推荐(0)

2014年8月8日

摘要: No limit to transaction count, so it is a recursive sum calculation. Take care of boundary condition.class Solution {public: int maxProfit(vector &... 阅读全文
posted @ 2014-08-08 14:31 Tonix 阅读(162) 评论(0) 推荐(0)

摘要: Also the very first problem on EPI.class Solution {public: int maxProfit(vector &prices) { size_t len = prices.size(); if (len = pric... 阅读全文
posted @ 2014-08-08 14:20 Tonix 阅读(159) 评论(0) 推荐(0)

摘要: "that are all of the same length" is the key. This statement makes everything much simpler. And, please take care that L may contain duplicated string... 阅读全文
posted @ 2014-08-08 13:54 Tonix 阅读(122) 评论(0) 推荐(0)

摘要: Since it is a "return all" problem, we can use DFS. But brutal DFS got a TLE. So pruning is required.I referred tohttp://fisherlei.blogspot.com/2013/1... 阅读全文
posted @ 2014-08-08 08:09 Tonix 阅读(186) 评论(0) 推荐(0)

摘要: My first solution was DFS - TLE. Apparently, DFS with TLE usually means DP.1D DP + Rolling Array:class Solution {public: bool wordBreak(string s, u... 阅读全文
posted @ 2014-08-08 07:14 Tonix 阅读(182) 评论(0) 推荐(0)

2014年8月6日

摘要: I think it is natural for an algorithm rookie that when facing a challenging problem, a rookie may fall into her\his algorithm dictionary - she focuse... 阅读全文
posted @ 2014-08-06 13:51 Tonix 阅读(153) 评论(0) 推荐(0)

摘要: Your intuition would tell you that there's a O(n) solution. Actually it is another stack-based problem to solve.class Solution {public: struct Rec ... 阅读全文
posted @ 2014-08-06 13:40 Tonix 阅读(154) 评论(0) 推荐(0)

摘要: It took me +20 submissions to get AC... Actually the statement is too vague. I would rather ask for requirements f2f.Apparently the code below can be ... 阅读全文
posted @ 2014-08-06 07:39 Tonix 阅读(139) 评论(0) 推荐(0)

摘要: 2D DP is an intuitive solution of course, but I got an MLE error, so I simplified it into a 1D DP:class Solution {public: void goDp(vector &dp, int... 阅读全文
posted @ 2014-08-06 05:56 Tonix 阅读(163) 评论(0) 推荐(0)

摘要: Another list manipulation problem.class Solution {public: ListNode *reverseKGroup(ListNode *head, int k) { if (!head) return head; if... 阅读全文
posted @ 2014-08-06 04:46 Tonix 阅读(158) 评论(0) 推荐(0)

2014年8月5日

摘要: An example of in-order traversal application. My intuition is that, we have to serialize it into an array and check, but in-order traversal does exact... 阅读全文
posted @ 2014-08-05 01:47 Tonix 阅读(144) 评论(0) 推荐(0)

2014年8月4日

摘要: DFS + Backtrace + Pruningclass Solution {public: vector > visited; bool checkPos(vector > &board, char c, int currX, int currY) { ... 阅读全文
posted @ 2014-08-04 14:43 Tonix 阅读(191) 评论(0) 推荐(0)

2014年8月3日

摘要: An intuitive 2D DP: dp[i][j] = min(grid[i-1][j-1] + dp[i-1][j], grid[i-1][j-1] + dp[i][j+1])class Solution {public: int minPathSum(vector > &grid) ... 阅读全文
posted @ 2014-08-03 07:30 Tonix 阅读(195) 评论(0) 推荐(0)