Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 思路:不能用额外空间,就用矩阵的第一行和第一列来标记这一行或这一列是否需要置0. 用两个bool量记录第一行和第一列是否需要置0 大神的代码和我的代码都是这个思路,但是我在画0的时候是行列分开处理的,大神的代码是一起处理的 void setZeroes(vector<vector<int> > &…
题目: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement us…
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Example 1: Input: [ [1,1,1], [1,0,1], [1,1,1] ] Output: [ [1,0,1], [0,0,0], [1,0,1] ] Example 2: Input: [ [0,1,2,0], [3,4,5,2], [1,3,1,5]…
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 解题思路: 用两个boolean数组row col表示行列是否有零即可,JAVA实现如下: public void setZeroes(int[][] matrix) { if (matrix.length == 0 || matrix[0].length == 0) return; boolean[] row…
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m + n) space, but still…
给定一个m x n的矩阵,如果某个元素为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. 分析:最直接想到的就是遍历该矩阵,每遇到0就把它所在的行和列全部置0,但这是错的,因为这样会引入新的0到矩阵中.下一个比较容易相到的方法是:遍历矩阵,每遇到一个0元素就把它所在的行和列标记起来,最后再遍历matrix,若某元素的行或者列…
今天看到CSDN博客的勋章换了图表,同一时候也添加显示了博客等级,看起来都听清新的,感觉不错! [题目] Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space? A straight forward solution using O(mn) sp…
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O…