2013年11月13日

Merge Sorted Array

摘要: 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 aremandnrespectively. 1 public class Solution { 2 public void merge(int A[], int m, int B[], i... 阅读全文

posted @ 2013-11-13 08:19 Step-BY-Step 阅读(103) 评论(0) 推荐(0) 编辑

Remove Duplicates from Sorted List II

摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.Solution: 指针操作。如果当前val和下一个val相等,则将per指针一直移到和这些val不等的位 阅读全文

posted @ 2013-11-13 07:25 Step-BY-Step 阅读(165) 评论(0) 推荐(0) 编辑

Search in Rotated Sorted Array II

摘要: 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.Solution:唯一需要判断的地方是如果刚好在duplicate的地方分开了怎么办,这样的时候 mid没有意义了。 1 public class Solution { 2 public b 阅读全文

posted @ 2013-11-13 06:20 Step-BY-Step 阅读(140) 评论(0) 推荐(0) 编辑

Remove Duplicates from Sorted Array II

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

posted @ 2013-11-13 03:56 Step-BY-Step 阅读(191) 评论(0) 推荐(0) 编辑

Subsets II

摘要: Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.... 阅读全文

posted @ 2013-11-13 03:42 Step-BY-Step 阅读(157) 评论(0) 推荐(0) 编辑

Subsets

摘要: Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,IfS=[1,2,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]这题和Combinations一样。 也可以用位运算做。 ... 阅读全文

posted @ 2013-11-13 02:50 Step-BY-Step 阅读(104) 评论(0) 推荐(0) 编辑

导航