上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 38 下一页
摘要: 题目: 解答: A. 先确定第一行和第一列是否需要清零; B. 扫描剩下的矩阵元素,如果遇到了0,就将对应的第一行和第一列上的元素赋值为0; C. 根据第一行和第一列的信息,已经可以将剩下的矩阵元素赋值为结果所需的值了; D. 根据1中确定的状态,处理第一行和第一列; 1 class Solutio 阅读全文
posted @ 2020-05-05 15:53 梦醒潇湘 阅读(189) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 int minPathSum(vector<vector<int>>& grid) 4 { 5 for(int i = 0; i < grid.size(); i++) 6 { 7 for(int j = 0; j < g 阅读全文
posted @ 2020-05-05 15:48 梦醒潇湘 阅读(178) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) 4 { 5 int m = obstacleGrid.size(); 6 int n = ob 阅读全文
posted @ 2020-05-05 15:44 梦醒潇湘 阅读(92) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 int uniquePaths(int m, int n) 4 { 5 vector<vector<int>> dp(m,vector<int>(n)); 6 7 for (int i = 0; i < n; i++) 8 阅读全文
posted @ 2020-05-05 15:39 梦醒潇湘 阅读(133) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * int end; 6 * Interval() : start(0), end(0) {} 7 * Interval(int 阅读全文
posted @ 2020-05-05 15:32 梦醒潇湘 阅读(238) 评论(0) 推荐(0)
摘要: 题目: 解答: (1)如果某一个作为 起跳点 的格子可以跳跃的距离是 3,那么表示后面 3 个格子都可以作为 起跳点。(2)可以对每一个能作为 起跳点 的格子都尝试跳一次,把 能跳到最远的距离 不断更新。(3)如果可以一直跳到最后,就成功了。 1 class Solution { 2 public: 阅读全文
posted @ 2020-05-05 15:27 梦醒潇湘 阅读(180) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 public: 3 vector<vector<int>> generateMatrix(int n) 4 { 5 vector< vector<int> > matrix(n, vector<int>(n)); 6 if (n == 0) 阅读全文
posted @ 2020-05-05 15:24 梦醒潇湘 阅读(160) 评论(0) 推荐(0)
摘要: 题目: 解答: 迭代法。 1 class Solution { 2 public: 3 4 vector<int> spiralOrder(vector<vector<int> >& matrix) 5 { 6 vector<int> result; 7 if (matrix.empty()) 8 阅读全文
posted @ 2020-05-05 15:23 梦醒潇湘 阅读(154) 评论(0) 推荐(0)
摘要: 题目: 解答: 方法 1 :转置加翻转 最直接的想法是先转置矩阵,然后翻转每一行。这个简单的方法已经能达到最优的时间复杂度O(N^2)。 1 class Solution { 2 public void rotate(int[][] matrix) { 3 int n = matrix.length 阅读全文
posted @ 2020-05-05 15:14 梦醒潇湘 阅读(161) 评论(0) 推荐(0)
摘要: 题目: 解答: 方法一: 方法二: 方法三 : 1 class Solution { 2 public: 3 int firstMissingPositive(vector<int>& nums) 4 { 5 for (int i = 0; i < nums.size(); i++) 6 { 7 w 阅读全文
posted @ 2020-05-05 15:02 梦醒潇湘 阅读(144) 评论(0) 推荐(0)
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 38 下一页