摘要: 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].这里主要注意的是STL的... 阅读全文
posted @ 2014-04-13 22:40 linyx 阅读(159) 评论(0) 推荐(0) 编辑
摘要: GDB调试不能打印stl容器内容,下载此文件,将之保存为~/.gdbinit就可以使用打印命令了。打印list用plist命令,打印vector用pvector,依此类推。(gdb) pvector curelem[0]: $5 = 3elem[1]: $6 = 9Vector size = 2Vector capacity = 2Element type = std::allocator::pointer 阅读全文
posted @ 2014-04-12 15:37 linyx 阅读(852) 评论(0) 推荐(0) 编辑
摘要: Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Method I解决思路和求最短不减子序列类似:开一个数组lines,第k个位置存放的是有k个点的直线,由... 阅读全文
posted @ 2014-04-11 16:45 linyx 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 这个题相当经典。很多题目都可以等价过来。一、简单的O(n^2)的算法 很容易想到用动态规划做。设lis[]用于保存第1~i元素元素中最长不下降序列的长度,则lis[i]=max(lis[j])+1,且num[i]>num[j],i>j。然后在lis[]中找到最大的一个值,时间复杂度是O(n^2)。int Longest_Increasing(int num[],int n){ int lis[n],i,j; for(i=0;inum[j]&&lis[j]+1>lis[i]) lis[i]=lis[j]+1; } int ma... 阅读全文
posted @ 2014-04-10 15:04 linyx 阅读(448) 评论(0) 推荐(0) 编辑
摘要: The algorithm for evaluating any postfix expression is fairly straightforward:While there are input tokens leftRead the next token from input.If the t... 阅读全文
posted @ 2014-04-10 14:17 linyx 阅读(188) 评论(0) 推荐(0) 编辑
摘要: Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be ch... 阅读全文
posted @ 2014-04-10 12:23 linyx 阅读(347) 评论(0) 推荐(0) 编辑
摘要: Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the p... 阅读全文
posted @ 2014-04-10 11:34 linyx 阅读(190) 评论(0) 推荐(0) 编辑
摘要: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Did you use extra space?A straight forward solution using... 阅读全文
posted @ 2014-04-09 14:38 linyx 阅读(181) 评论(0) 推荐(0) 编辑
摘要: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted fr... 阅读全文
posted @ 2014-04-09 11:54 linyx 阅读(197) 评论(0) 推荐(0) 编辑
摘要: A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any p... 阅读全文
posted @ 2014-04-08 19:10 linyx 阅读(140) 评论(0) 推荐(0) 编辑