摘要: There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from stationito its next station (i+1). You begin the journey with an empty tank at one of the gas stations.Return the starting gas 阅读全文
posted @ 2013-11-15 13:32 假日笛声 阅读(535) 评论(0) 推荐(0) 编辑
摘要: The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, forn= 3):"123""132""213""231""312""321"Givennandk, return thekthpermutation sequence.Not 阅读全文
posted @ 2013-11-14 16:27 假日笛声 阅读(685) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],]BFS ... 阅读全文
posted @ 2013-11-12 12:46 假日笛声 阅读(527) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.Solution: 1 ListNode *deleteDuplicates(ListNode *head 阅读全文
posted @ 2013-11-11 10:26 假日笛声 阅读(169) 评论(0) 推荐(0) 编辑
摘要: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"isnota palindrome.Note:Have you consider that the string might be empty? This is a good question to 阅读全文
posted @ 2013-11-10 14:02 假日笛声 阅读(460) 评论(0) 推荐(0) 编辑
摘要: Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.Summary: It's easy, but should be careful about corner cases, like m is 0 阅读全文
posted @ 2013-11-10 05:53 假日笛声 阅读(365) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑