附上代码: 1voidsetZeroes(vector<vector<int>>&matrix) {2intn = matrix.size(), m = matrix[0].size();3int*row = (int*)malloc((n /31+2) *sizeof(int));4int*col = (int*)malloc((m /31+2) *sizeof(int));57for(inti =0; i < n /31+2; i ++) row[i] =0;8for(inti ...
Can you solve this real interview question? Set Matrix Zeroes - Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's. You must do it in place [https://en.wikipedia.org/wiki/In-place_algorithm]. Example 1: [
Can you solve this real interview question? Set Matrix Zeroes - Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's. You must do it in place [https://en.wikipedia.org/wiki/In-place_algorithm]. Example 1: [
matrix[0][i]=0; }if(firstCol) {for(inti=0;i<n;i++) matrix[i][0]=0; }
public class Code073 { public static void setZeroes(int[][]matrix){ HashSet<Integer>row=new HashSet<>(); HashSet<Integer>col=new HashSet<>(); for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[0].length; j++) { ...
然后matrix[1][0]==0,matrix[2][0]==0,matrix[3][0]==0 导致: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 【注意】 本题要求:Do it in place. 【代码】 ...
【摘要】 Leetcode 题目解析之 Set Matrix Zeroes 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(m__n) space is probably a bad idea. ...
void setZeroes2(vector<vector<int> > &matrix) { int row = matrix.size(); if (row < 1) return; int col = matrix[0].size(); bool firstRowhasZero = false; bool firstColhasZero = false; for (int i = 0; i < row && !firstColhasZero; i++) ...
public void setZeroes(int[][] matrix) { int m = matrix.length, n = matrix[0].length; int row0 = 1, column0 = 1; // first row for (int i = 0; i < n; i++) { if (0 == matrix[0][i]) { row0 = 0; } }
LeetCode 73. Set Matrix Zeroes Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. answer: class Solution { public: void setZeroes(vector<vector<int>>& matrix) { set<int> mSet;