摘要: Summary: Basic staff, need to check if goes up along the tree, that's the difference to pre-order traverse. 1 vector postorderTraversal(TreeNode *root) { 2 vector seq; 3 if(root == NULL) 4 return seq; 5 stack nodes; 6 nodes.push(root); 7 TreeNo... 阅读全文
posted @ 2013-11-09 15:50 假日笛声 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,IfS=[1,2,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]Summary: Recursive approach, ... 阅读全文
posted @ 2013-11-09 15:18 假日笛声 阅读(175) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order ofO(logn).If the target is not found in the array, return[-1, -1].For example,Given[5, 7, 7, 8, 8, 10]and target value 8,return[3, 4].Summary: 阅读全文
posted @ 2013-11-09 14:50 假日笛声 阅读(839) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorder it to{1,4,2,3}.Solution: make sure the last element points to NULL in the new list; 1 void reorderList(ListNode *head) 阅读全文
posted @ 2013-11-09 13:54 假日笛声 阅读(387) 评论(0) 推荐(0) 编辑