摘要: Two SumGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index 阅读全文
posted @ 2014-03-22 23:00 flowerkzj 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 这一篇是两个全集,从2个排序列表到k个排序列表。先从2个入手。Merge Two Sorted ListsMerge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.思路跟数组时类似,主要都是比较、链表插入操作。代码如下: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * ... 阅读全文
posted @ 2014-03-22 15:48 flowerkzj 阅读(283) 评论(0) 推荐(0) 编辑
摘要: Merge Sorted ArrayGiven two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal tom+n) to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.最简单粗暴的思路:1. 开辟数组空间C用以 阅读全文
posted @ 2014-03-22 02:19 flowerkzj 阅读(178) 评论(0) 推荐(0) 编辑