straight forward version
| 30 | |
| 31 | // straight forward version |
| 32 | void setZeroes2(vector<vector<int>>& matrix) { |
| 33 | vector<bool> icz (matrix.size(), false); |
| 34 | if (icz.size() == 0) return; |
| 35 | vector<bool> jcz (matrix[0].size(), false); |
| 36 | for (int i=0; i<matrix.size(); i++) { |
| 37 | for (int j=0; j<matrix[0].size(); j++) { |
| 38 | if ( matrix[i][j] == 0 ) { |
| 39 | icz[i] = true; |
| 40 | jcz[j] = true; |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | for (int i=0; i<matrix.size(); i++) { |
| 45 | for (int j=0; j<matrix[0].size(); j++) { |
| 46 | if ( icz[i] or jcz[j] ) { |
| 47 | matrix[i][j] = 0; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | |
| 54 | // constant space |
| 55 | void setZeroes(vector<vector<int>>& matrix) { |
nothing calls this directly
no outgoing calls
no test coverage detected