摘要: Sort a linked list using insertion sort. 1 public ListNode insertionSortList(ListNode head) { 2 // IMPORTANT: Please reset any member data you declared, as 3 // the same Solution instance will be reused for each test case. 4 if(head == null){ 5 return head; 6 ... 阅读全文
posted @ 2013-11-16 22:10 feiling 阅读(1271) 评论(0) 推荐(0)
摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the value if the key is not 阅读全文
posted @ 2013-11-16 17:10 feiling 阅读(1532) 评论(0) 推荐(1)
摘要: Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].Note:Recursive solution is trivial, could you do it iteratively?[解题思路]后序遍历的非递归相对来说比较难,根节点需要在其左右孩子都访问结束后才能被访问,因此对于任一节点,先将其入栈,如果p不存在左孩子和右孩子,则可以直接访问它;或者p存在... 阅读全文
posted @ 2013-11-16 10:53 feiling 阅读(375) 评论(0) 推荐(0)