Skip to content

Commit 3a4236e

Browse files
Update Set Matrix Zero.cpp
1 parent cb476d7 commit 3a4236e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

2D Arrays/Set Matrix Zero.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
/*______________________________________________________________________PROBLEM___________________________________________________________*/
2+
3+
/*Given an m x n matrix. If an element is 0, set its entire row and column to 0. Do it in-place.
4+
Follow up:
5+
6+
A straight forward solution using O(mn) space is probably a bad idea.
7+
A simple improvement uses O(m + n) space, but still not the best solution.
8+
Could you devise a constant space solution?
9+
10+
EXAMPLE 1:
11+
Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
12+
Output: [[1,0,1],[0,0,0],[1,0,1]]
13+
14+
EXAMPLE 2:
15+
Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
16+
Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
17+
18+
19+
20+
Constraints:
21+
22+
m == matrix.length
23+
n == matrix[0].length
24+
1 <= m, n <= 200
25+
-231 <= matrix[i][j] <= 231 - 1
26+
*/
27+
28+
129
class Solution {
230
public:
331
void setZeroes(vector<vector<int>>& m) {

0 commit comments

Comments
 (0)