上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 43 下一页
摘要: 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 阅读(189) 评论(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 阅读(488) 评论(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 阅读(225) 评论(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) 编辑
摘要: Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.[解题思路]初始的想法是类似于求倒数第k个数,结果发现k可能会比len大,到网上搜索了下:从head节点开始跑,一直跑到尾节点,得到len,将尾节点的next指针指向head,接着跑(len -n) % len步,断开这里需注意(len -n) % 阅读全文
posted @ 2013-08-12 23:38 feiling 阅读(288) 评论(0) 推荐(0) 编辑
摘要: Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].[解题思路]这里使用Insert interval的解题过程,将待合并的interval依次插入 1 /** 2 * Definition for an interval. 3 * public class Interval { 4 * int start; 5 * int end; 6 * ... 阅读全文
posted @ 2013-08-12 22:23 feiling 阅读(346) 评论(0) 推荐(0) 编辑
摘要: Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Given intervals[1,3],[6,9], insert and merge[2,5]in as[1,5],[6,9].Example 2:Given[1,2],[3,5],[6,7],[8 阅读全文
posted @ 2013-08-12 22:08 feiling 阅读(229) 评论(0) 推荐(0) 编辑
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 43 下一页