原网址:
http://www.jiuzhang.com/problem/78/
问题详情
给出一个无重叠的按照区间起始端点排序的区间列表。
在列表中插入一个新的区间,你要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。
在线评测本题:
http://www.lintcode.com/zh-cn/problem/insert-interval/
解答
...
分类:
编程语言 时间:
2015-07-18 11:04:00
阅读次数:
151
http://www.lintcode.com/zh-cn/problem/unique-paths-ii/在上一题的基础上加入了障碍物。同样可采用递归实现,递推公式不变,但是需要加入对障碍物的判断。下面是实现的代码: 1 #include 2 #include 3 class Solution.....
分类:
其他好文 时间:
2015-07-16 19:19:56
阅读次数:
193
http://www.lintcode.com/zh-cn/problem/unique-paths/递推公式:f[m][n] = f[m-1][n]+f[m][n-1]可采用DP或者记忆化的递归实现。下面是递归实现的代码: 1 #include 2 class Solution { 3 publ....
分类:
其他好文 时间:
2015-07-16 19:10:46
阅读次数:
168
法1:二分 1 class Solution { 2 public: 3 /** 4 * @param x: An integer 5 * @return: The sqrt of x 6 */ 7 int sqrt(int x) { 8 ...
分类:
其他好文 时间:
2015-07-16 18:24:38
阅读次数:
138
N-QueensThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, retu...
分类:
其他好文 时间:
2015-07-14 20:24:49
阅读次数:
117
|题目给一个01矩阵,求不同的岛屿的个数。0代表海,1代表岛,如果两个1相邻,那么这两个1属于同一个岛。我们只考虑上下左右为相邻。|在线测试本题http://www.lintcode.com/zh-cn/problem/number-of-islands/|难度容易
分类:
其他好文 时间:
2015-07-13 23:42:08
阅读次数:
312
题目描述假设一个旋转排序的数组其起始位置是未知的(比如0 1 2 4 5 6 7 可能变成是4 5 6 7 0 1 2)。你需要找到其中最小的元素。http://www.lintcode.com/zh-cn/problem/find-minimum-in-rotated-sorted-array/解题思路基本思想采用二分查找,不过首先要判断这个排序数组是否直接有序,如果是0 1 2 3 4 5 6...
分类:
编程语言 时间:
2015-07-12 09:46:57
阅读次数:
162
1 /** 2 * Definition for a point. 3 * struct Point { 4 * int x; 5 * int y; 6 * Point() : x(0), y(0) {} 7 * Point(int a, int b) ...
分类:
其他好文 时间:
2015-07-11 22:40:44
阅读次数:
243
1 class Solution { 2 public: 3 /** 4 * @param nums: a vector of integers 5 * @return: an integer 6 */ 7 int findMissing(ve...
分类:
其他好文 时间:
2015-07-11 22:38:33
阅读次数:
172
样例题目来自LintCode, 给出中序遍历:[1,2,3]和前序遍历:[2,1,3]. 返回如下的树: 2
/ 1 3代码实现/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int va...
分类:
其他好文 时间:
2015-07-11 18:39:04
阅读次数:
137