摘要:
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 ... 阅读全文
摘要:
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... 阅读全文
摘要:
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 阅读全文
摘要:
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... 阅读全文