摘要: 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 are m and n respectively.class Solution {public: void merge(int A[], int m, int B[], int n) {... 阅读全文
posted @ 2013-07-09 21:58 一只会思考的猪 阅读(139) 评论(0) 推荐(0) 编辑
摘要: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n satisfy the following condition: 1 ? m ? n ? length of list.class Solution {public: void rev 阅读全文
posted @ 2013-07-09 21:47 一只会思考的猪 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? 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].class Solution {public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ sol 阅读全文
posted @ 2013-07-09 21:07 一只会思考的猪 阅读(113) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->1->2->3, return 2->3.class Solution {public: ListNode *deleteDuplica 阅读全文
posted @ 2013-07-09 20:24 一只会思考的猪 阅读(154) 评论(0) 推荐(0) 编辑