Thanks for using LeetCode! To view this solution you must subscribe to premium.Subscribe Ln 1, Col 1 You need to Login / Sign up to run or submit Case 1Case 2 matrix = [[1,1,1],[1,0,1],[1,1,1]] 1 2 [[1,1,1],[1,0,1],[1,1,1]] [[0,1,2,0],[3,4,5,2],...
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 =0; i < ...
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; }
【摘要】 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. ...
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++) { ...
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;
* 题号: Set Matrix Zeroes * 来源:http://oj.leetcode.com/problems/set-matrix-zeroes/ * 结果:AC * 来源:LeetCode * 总结: ***/ #include <iostream> #include <stdio.h> #include <vector> using namespace std; class Solution { public: ...