摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3. 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * Lis 阅读全文
posted @ 2013-08-13 23:08 feiling 阅读(190) 评论(0) 推荐(0) 编辑
摘要: Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.Note:You are not suppose to use the l 阅读全文
posted @ 2013-08-13 21:52 feiling 阅读(491) 评论(0) 推荐(0) 编辑
摘要: 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], []] 1 public class Solution { 2 ... 阅读全文
posted @ 2013-08-13 21:29 feiling 阅读(243) 评论(0) 推荐(0) 编辑
摘要: Given an array of words and a lengthL, format the text such that each line has exactlyLcharacters and is fully (left and right) justified.You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces' 'when necessary so that each line 阅读全文
posted @ 2013-08-13 10:58 feiling 阅读(226) 评论(0) 推荐(0) 编辑
摘要: Given a number represented as an array of digits, plus one to the number. 1 public class Solution { 2 public int[] plusOne(int[] digits) { 3 // Start typing your Java solution below 4 // DO NOT write main() function 5 int len = digits.length; 6 digits[len - 1] += ... 阅读全文
posted @ 2013-08-13 10:57 feiling 阅读(191) 评论(0) 推荐(0) 编辑
摘要: Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".[解题思路]将a,b转成10进制相加得到结果再转成二进制,可以过small,跑large时溢出"10100000100100110110010000010101111011011001101110111111111101000000101111001110001111100001101", "11010 阅读全文
posted @ 2013-08-13 10:13 feiling 阅读(371) 评论(0) 推荐(0) 编辑
摘要: Merge 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 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { 7 * v... 阅读全文
posted @ 2013-08-13 09:36 feiling 阅读(239) 评论(0) 推荐(0) 编辑