File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public void setZeroes (int [][] matrix ) {
3+ Boolean isCol = false ;
4+ int R = matrix .length , C = matrix [0 ].length ;
5+ for (int i = 0 ; i < R ; i ++) {
6+ if (matrix [i ][0 ] == 0 ) {
7+ isCol = true ;
8+ }
9+ for (int j = 1 ; j < C ; j ++) {
10+ if (matrix [i ][j ] == 0 ) {
11+ matrix [0 ][j ] = 0 ;
12+ matrix [i ][0 ] = 0 ;
13+ }
14+ }
15+ }
16+ for (int i = 1 ; i < R ; i ++) {
17+ for (int j = 1 ; j < C ; j ++) {
18+ if (matrix [i ][0 ] == 0 || matrix [0 ][j ] == 0 ) {
19+ matrix [i ][j ] = 0 ;
20+ }
21+ }
22+ }
23+ if (matrix [0 ][0 ] == 0 ) {
24+ for (int j = 0 ; j < C ; j ++) {
25+ matrix [0 ][j ] = 0 ;
26+ }
27+ }
28+ if (isCol ) {
29+ for (int i = 0 ; i < R ; i ++) {
30+ matrix [i ][0 ] = 0 ;
31+ }
32+ }
33+ }
34+ }
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
105105| 1200 | [ Minimum Absolute Difference] ( https://leetcode.com/problems/minimum-absolute-difference/ ) | [ Python] ( ./python/SmallestDifference.py ) | O(n) | O(1) | Easy | Array |
106106| 532 | [ K-diff Pairs in an Array] ( https://leetcode.com/problems/k-diff-pairs-in-an-array/ ) | [ C++] ( ./C++/k-diff-pairs-in-an-array.cpp ) | O(n) | O(n) | Medium | Array |
107107| 152 | [ Maximum Product Subarray] ( https://leetcode.com/problems/maximum-product-subarray/ ) | [ Javascript] ( ./JavaScript/152.Maximum-Product-Subarray.js ) | O(n) | O(n) | Medium | Array |
108+ | 073 | [ Set-Matrix-Zeroes] ( https://leetcode.com/problems/set-matrix-zeroes/ ) | [ Java] ( ./Java/set-matrix-zeroes.java ) | O(MN) | O(1) | Medium | Array |
108109
109110
110111<br />
You can’t perform that action at this time.
0 commit comments