摘要: The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code s 阅读全文
posted @ 2014-02-13 14:30 Razer.Lu 阅读(287) 评论(0) 推荐(0) 编辑
摘要: 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.The solution set must not contain duplicate subsets.For example,IfS=[1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]解题思路: 跟subset 基... 阅读全文
posted @ 2014-02-13 14:04 Razer.Lu 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 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]. 1 public class Solution { 2 public int removeDuplicates(int[] A) { 3 if(A == null || A.length == 0) 阅读全文
posted @ 2014-02-13 13:24 Razer.Lu 阅读(170) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie,a≤b≤c≤d)The solution set must not contain duplicate quadruplets. . 阅读全文
posted @ 2014-02-13 13:07 Razer.Lu 阅读(260) 评论(0) 推荐(0) 编辑