摘要:
Q:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.Note:Givenm,nsatisfy the following condition:1 next; count++; } temp = tail = cur; cur = cur->next; ... 阅读全文
摘要:
Q:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.A: 像mergesort一样,两两merge。递归版本: ListNode *merge(ListNode *list1,ListNode *list2) { if(!list1) return list2; if(!list2) return list1; ListNode *head; ... 阅读全文
摘要:
Q:Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the array.A:有重复的元素。bool bisearch(int A[],int begin,int end,int target){ if(begin>end) return false; 阅读全文