摘要:
原题地址基本动态规划题代码: 1 int minPathSum(vector > &grid) { 2 if (grid.empty() || grid[0].empty()) return 0; 3 4 int m = grid.size(); 5 int n = grid[0].s... 阅读全文
posted @ 2015-01-27 18:50
李舜阳
阅读(157)
评论(0)
推荐(0)
摘要:
原题地址基本动态规划题代码: 1 int uniquePathsWithObstacles(vector > &obstacleGrid) { 2 if (obstacleGrid.empty() || obstacleGrid[0].empty()) return 0; 3 ... 阅读全文
posted @ 2015-01-27 18:31
李舜阳
阅读(144)
评论(0)
推荐(0)
摘要:
原题地址基本动态规划题代码: 1 int uniquePaths(int m, int n) { 2 vector sum(n, 0); 3 4 sum[n - 1] = 1; 5 for (int i = m - 1; i >= 0... 阅读全文
posted @ 2015-01-27 18:24
李舜阳
阅读(171)
评论(0)
推荐(0)
摘要:
原题地址我一直不太理解为什么叫rotate,翻译成"旋转"吧,似乎也不像啊。比如:1->2->3->4->5->NULL向右旋转2的距离,变成了:4->5->1->2->3->NULL后来琢磨半天+跟人讨论,似乎可以这么理解"rotate"1. 循环shift。这个比较容易理解。2. 环旋转。意思是... 阅读全文
posted @ 2015-01-27 18:06
李舜阳
阅读(258)
评论(0)
推荐(0)
摘要:
原题地址一个一个模拟肯定要超时,只有生算找规律呗。比如n=4,k=10,先将n=4的所有排列写出来:(1) 1 2 3 4(2) 1 2 4 3(3) 1 3 2 4(4) 1 3 4 2(5) 1 4 2 3(6) 1 4 3 2(7) 2 1 3 4(8) 2 1 4 3(9) ... 阅读全文
posted @ 2015-01-27 17:18
李舜阳
阅读(323)
评论(0)
推荐(0)
摘要:
原题地址相比于Spiral Matrix(参见这篇文章)要简单一些,因为是方阵,所以代码简洁一些。注意当n是奇数的时候,中心小块要单独赋值(代码21行)代码: 1 vector > generateMatrix(int n) { 2 vector > matrix(n, vector(n, 0)... 阅读全文
posted @ 2015-01-27 15:32
李舜阳
阅读(157)
评论(0)
推荐(0)
摘要:
原题地址经典题目。所有数字异或,剩下的就是只出现一次的数字,因为其他出现两次的数字都没啦。T ^ T = 0代码:1 int singleNumber(int A[], int n) {2 int res = 0;3 4 for (int i = 0; i < n; i++)5 re... 阅读全文
posted @ 2015-01-27 15:19
李舜阳
阅读(149)
评论(0)
推荐(0)
摘要:
原题地址排序+DFS与Combination Sum II(参见这篇文章)不同的地方在于,重复的数字可以使用多次,无所谓啦,反正代码几乎都一样。代码: 1 vector > res; 2 3 void dfs(vector &candidates, vector ans, int pos, int... 阅读全文
posted @ 2015-01-27 15:16
李舜阳
阅读(148)
评论(0)
推荐(0)
摘要:
原题地址跟Jump Game II(见这篇文章)不同的地方在于,只需要判断能否到达终点即可遍历每个位置,更新能够到达的范围,最后看看范围是否覆盖了终点代码: 1 bool canJump(int A[], int n) { 2 int range = 0; 3 int... 阅读全文
posted @ 2015-01-27 14:54
李舜阳
阅读(159)
评论(0)
推荐(0)
摘要:
原题地址简单模拟,用t,b,l,r分别表示当前的上下左右四个边界,然后遍历即可代码: 1 vector spiralOrder(vector > &matrix) { 2 if (matrix.empty() || matrix[0].empty()) return vector(); 3 4... 阅读全文
posted @ 2015-01-27 14:43
李舜阳
阅读(266)
评论(0)
推荐(0)

浙公网安备 33010602011771号