摘要: 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) 编辑
摘要: Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4]. Return its length:4.Your algorithm should run in O(n) complexity.large data TLE 1 public class Solution 阅读全文
posted @ 2013-08-12 11:24 feiling 阅读(204) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum of all root-to-leaf numbers.For example, 1 / \ 2 3The root-to-leaf path1->2represents the number12.T 阅读全文
posted @ 2013-08-12 10:45 feiling 阅读(383) 评论(0) 推荐(0) 编辑