Tony's Log

Algorithms, Distributed System, Machine Learning

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

2014年8月3日

摘要: Corner cases!class Solution {public: ListNode *deleteDuplicates(ListNode *head) { if (!head) return head; if (!head->next) return hea... 阅读全文
posted @ 2014-08-03 07:04 Tonix 阅读(171) 评论(0) 推荐(0)

摘要: Nothing special. A typical list manipulation problem.class Solution {public: ListNode *partition(ListNode *head, int x) { if (!head) return ... 阅读全文
posted @ 2014-08-03 06:39 Tonix 阅读(131) 评论(0) 推荐(0)

2014年8月2日

摘要: It is all about corner cases.class Solution {public: vector retv; bool isValid(string &sub) { unsigned cnt = sub.length(); if (... 阅读全文
posted @ 2014-08-02 11:07 Tonix 阅读(182) 评论(0) 推荐(0)

摘要: Lexicographicallyalgorithms:1. Iterate array from back to front, and find the first decreasing point: 1,2,4,3 -- 42. Iterate array from back to front,... 阅读全文
posted @ 2014-08-02 03:42 Tonix 阅读(141) 评论(0) 推荐(0)

摘要: First I implemented it by QuickSort, but got a TLE:class Solution {public: struct Pair { Pair(ListNode *pS, ListNode *pE) : pStart(pS), p... 阅读全文
posted @ 2014-08-02 03:19 Tonix 阅读(146) 评论(0) 推荐(0)

2014年8月1日

摘要: Greedy, Greedy, Greedy.. It is all about maximum interval update.One trick is, we start looping over each element from the one nearest to end to farth... 阅读全文
posted @ 2014-08-01 12:07 Tonix 阅读(125) 评论(0) 推荐(0)

摘要: A simulation problem. We simple walk through all reachable items until we cannot proceed.class Solution {public: bool canJump(int A[], int n) { ... 阅读全文
posted @ 2014-08-01 11:11 Tonix 阅读(114) 评论(0) 推荐(0)

摘要: Next time you see a numeric problem has a too straightforward solution, think about optimized one.Like this one: recursion\iteration is tooo slow. SoD... 阅读全文
posted @ 2014-08-01 05:09 Tonix 阅读(158) 评论(0) 推荐(0)

2014年7月31日

摘要: Just corner case..class Solution {public: ListNode *reverseBetween(ListNode *head, int m, int n) { if(m == n) return head; ListNode *... 阅读全文
posted @ 2014-07-31 08:06 Tonix 阅读(126) 评论(0) 推荐(0)

摘要: I fell in a deadloop, and didn't see the actual recursion pattern.Reference:http://fisherlei.blogspot.com/2013/03/leetcode-unique-binary-search-trees-... 阅读全文
posted @ 2014-07-31 07:19 Tonix 阅读(98) 评论(0) 推荐(0)

摘要: The only difference with version I is: one number can only be used once:class Solution {public: vector > ret; struct Rec { Rec() : sum... 阅读全文
posted @ 2014-07-31 03:40 Tonix 阅读(108) 评论(0) 推荐(0)

2014年7月29日

摘要: A very interesting numeric problem. It involves a lot tricks.Linear search (by +\-) is not feasible - too slow. So binary search is a good idea. Also ... 阅读全文
posted @ 2014-07-29 12:25 Tonix 阅读(150) 评论(0) 推荐(0)

2014年7月28日

摘要: Similar with "Longest Consecutive Sequence". Another usage to hashset.Take care of corner cases!class Solution {public: int firstMissingPositive(in... 阅读全文
posted @ 2014-07-28 12:27 Tonix 阅读(176) 评论(0) 推荐(0)

摘要: A BFS usage.class Solution {public: UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node) { if (!node) return NULL; UndirectedGr... 阅读全文
posted @ 2014-07-28 11:49 Tonix 阅读(132) 评论(0) 推荐(0)

摘要: Similar with "Climb stairs" but with more restrictions.// Ref: http://yucoding.blogspot.com/2013/01/leetcode-question-26-decode-ways.htmlclass Solu... 阅读全文
posted @ 2014-07-28 08:25 Tonix 阅读(132) 评论(0) 推荐(0)

摘要: Typical recurrsion\DFS problem. Just take care of memory use.class Solution {public: vector> ret; void go(int currMaxN, int currK, int k, unorde... 阅读全文
posted @ 2014-07-28 06:12 Tonix 阅读(154) 评论(0) 推荐(0)

2014年7月26日

摘要: Compared with I version, the tree could be incomplete. The only difference is that, we connect current node's child to next non-childrenless' node's f... 阅读全文
posted @ 2014-07-26 15:01 Tonix 阅读(150) 评论(0) 推荐(0)

摘要: Flood-Fill. BFS. But there's a trick. If we fill surrounded region directly, extra bookkeeping cost is needed - because we don't know whether that reg... 阅读全文
posted @ 2014-07-26 14:09 Tonix 阅读(190) 评论(0) 推荐(0)

2014年7月25日

摘要: Comparison-based sorting takes O(nlgn), so hashset is a good idea. After keeping records of all numbers in the hashset, you start checking each number... 阅读全文
posted @ 2014-07-25 01:14 Tonix 阅读(212) 评论(0) 推荐(0)

2014年7月23日

摘要: Nothing to hard to think. Just take care of boundary conditions.class Solution {public: string convert(string s, int nRows) { if(s.empty() |... 阅读全文
posted @ 2014-07-23 12:54 Tonix 阅读(168) 评论(0) 推荐(0)