File tree Expand file tree Collapse file tree 3 files changed +88
-0
lines changed Expand file tree Collapse file tree 3 files changed +88
-0
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,37 @@ class Solution {
117117}
118118```
119119
120+ ### ** JavaScript**
121+
122+ ``` js
123+ /**
124+ * @param {number[][]} matrix
125+ * @return {void} Do not return anything, modify matrix in-place instead.
126+ */
127+ var setZeroes = function (matrix ) {
128+ let m = matrix .length , n = matrix[0 ].length ;
129+ let rows = new Array (m).fill (false );
130+ let cols = new Array (n).fill (false );
131+ // 标记
132+ for (let i = 0 ; i < m; i++ ) {
133+ for (let j = 0 ; j < n; j++ ) {
134+ if (matrix[i][j] == 0 ) {
135+ rows[i] = true ;
136+ cols[j] = true ;
137+ }
138+ }
139+ }
140+ // 清零
141+ for (let i = 0 ; i < m; i++ ) {
142+ for (let j = 0 ; j < n; j++ ) {
143+ if (matrix[i][j] != 0 && (rows[i] || cols[j])) {
144+ matrix[i][j] = 0 ;
145+ }
146+ }
147+ }
148+ };
149+ ```
150+
120151### ** ...**
121152
122153```
Original file line number Diff line number Diff line change @@ -132,6 +132,37 @@ class Solution {
132132}
133133```
134134
135+ ### ** JavaScript**
136+
137+ ``` js
138+ /**
139+ * @param {number[][]} matrix
140+ * @return {void} Do not return anything, modify matrix in-place instead.
141+ */
142+ var setZeroes = function (matrix ) {
143+ let m = matrix .length , n = matrix[0 ].length ;
144+ let rows = new Array (m).fill (false );
145+ let cols = new Array (n).fill (false );
146+ // 标记
147+ for (let i = 0 ; i < m; i++ ) {
148+ for (let j = 0 ; j < n; j++ ) {
149+ if (matrix[i][j] == 0 ) {
150+ rows[i] = true ;
151+ cols[j] = true ;
152+ }
153+ }
154+ }
155+ // 清零
156+ for (let i = 0 ; i < m; i++ ) {
157+ for (let j = 0 ; j < n; j++ ) {
158+ if (matrix[i][j] != 0 && (rows[i] || cols[j])) {
159+ matrix[i][j] = 0 ;
160+ }
161+ }
162+ }
163+ };
164+ ```
165+
135166### ** ...**
136167
137168```
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[][] } matrix
3+ * @return {void } Do not return anything, modify matrix in-place instead.
4+ */
5+ var setZeroes = function ( matrix ) {
6+ let m = matrix . length , n = matrix [ 0 ] . length ;
7+ let rows = new Array ( m ) . fill ( false ) ;
8+ let cols = new Array ( n ) . fill ( false ) ;
9+ // 标记
10+ for ( let i = 0 ; i < m ; i ++ ) {
11+ for ( let j = 0 ; j < n ; j ++ ) {
12+ if ( matrix [ i ] [ j ] == 0 ) {
13+ rows [ i ] = true ;
14+ cols [ j ] = true ;
15+ }
16+ }
17+ }
18+ // 清零
19+ for ( let i = 0 ; i < m ; i ++ ) {
20+ for ( let j = 0 ; j < n ; j ++ ) {
21+ if ( matrix [ i ] [ j ] != 0 && ( rows [ i ] || cols [ j ] ) ) {
22+ matrix [ i ] [ j ] = 0 ;
23+ }
24+ }
25+ }
26+ } ;
You can’t perform that action at this time.
0 commit comments