MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / setZeroes

Method setZeroes

73. Set Matrix Zeroes/Solution.cpp:55–79  ·  view source on GitHub ↗

constant space

Source from the content-addressed store, hash-verified

53
54 // constant space
55 void setZeroes(vector<vector<int>>& matrix) {
56 bool frow = false;
57 for (int i=0; i<matrix.size(); i++) {
58 for (int j=0; j<matrix[0].size(); j++) {
59 if ( matrix[i][j] == 0 ) {
60 if (i == 0) frow = true;
61 else matrix[i][0] = 0;
62 matrix[0][j] = 0;
63 }
64 }
65 }
66 for (int i=1; i<matrix.size(); i++) {
67 for (int j=1; j<matrix[0].size(); j++) {
68 if (matrix[i][0] == 0 or matrix[0][j] == 0)
69 matrix[i][j] = 0;
70 }
71 }
72 if (matrix[0][0] == 0)
73 for (int i=0; i<matrix.size(); i++)
74 matrix[i][0] = 0;
75 if (frow)
76 for (int j=0; j<matrix[0].size(); j++)
77 matrix[0][j] = 0;
78
79 }
80};
81
82int main() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected