2014年4月4日

摘要: Problem link:http://oj.leetcode.com/problems/linked-list-cycle-ii/The solution has two step:Detecting the loop using faster/slower pointers.Finding the begining of the loop. After two pointers meet in step 1, keep one pointer and set anther to the head. Let the two pointers both go one step for each 阅读全文

posted @ 2014-04-04 23:48 卢泽尔 阅读(195) 评论(0) 推荐(0)

摘要: Problem link:http://oj.leetcode.com/problems/linked-list-cycle/We set two pointers: the faster pointer goes two steps each iteration, and the slower one goes one step.If the two pointers meet some time, it follows that there is a loop; otherwise, the faster pointer will touch the end of the singly l 阅读全文

posted @ 2014-04-04 23:38 卢泽尔 阅读(204) 评论(0) 推荐(0)

摘要: Problem link:http://oj.leetcode.com/problems/reorder-list/I think this problem should be a difficult problem, since it requries three classic algorithms on the single-linked list:Split a single-linked list into halvesReverse a single-linked listCombine two single-linked list into one alternatelySpli 阅读全文

posted @ 2014-04-04 07:35 卢泽尔 阅读(249) 评论(0) 推荐(0)

摘要: Problem Link:http://oj.leetcode.com/problems/binary-tree-preorder-traversal/Even iterative solution is easy, just use a stack storing the nodes not visited. Each iteration, pop a node and visited it, then push its right child and then left child into stack if possible.Note the special case that the 阅读全文

posted @ 2014-04-04 02:03 卢泽尔 阅读(247) 评论(0) 推荐(0)