摘要: Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should return length =5, and A is now[1,1,2,2,3].Solution: 1 int removeDuplicates(int A[], int n) { 2 if(n = 2){17 //remove A[i]18 ... 阅读全文
posted @ 2013-11-27 15:50 假日笛声 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6click to show hints.Hints:If y... 阅读全文
posted @ 2013-11-27 15:15 假日笛声 阅读(206) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).Solution: D 阅读全文
posted @ 2013-11-27 14:28 假日笛声 阅读(187) 评论(0) 推荐(0) 编辑
摘要: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.Solution: Uses map to recorde node mapping between old linked list and new linked list. 1 RandomListNode *copyRandomList(RandomListNod... 阅读全文
posted @ 2013-11-27 12:45 假日笛声 阅读(165) 评论(0) 推荐(0) 编辑