2013年11月22日

Insert Interval

摘要: 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-11-22 21:41 waruzhi 阅读(169) 评论(0) 推荐(0) 编辑

Implement strStr()

摘要: Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.思路:KMP算法。这道题理解KMP花了很久的时间,在求next函数的时候使用递推的思路,假如a[i] = k, 如果a[i+1] = a[k],那么a[i+2] != a[k+1]时,a[i+1] = k+1, 否则k = next[k],相当于在已匹配的子串部分再使用KMP。理解这一部分就基本理解全部了。代码: 1 void getNext... 阅读全文

posted @ 2013-11-22 19:41 waruzhi 阅读(162) 评论(0) 推荐(0) 编辑

导航