MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / setCellsToZero

Function setCellsToZero

javascript/0073-set-matrix-zeroes.js:90–104  ·  view source on GitHub ↗
(matrix, isColZero)

Source from the content-addressed store, hash-verified

88};
89
90var setCellsToZero = (matrix, isColZero) => {
91 const [rows, cols] = [matrix.length, matrix[0].length];
92
93 for (let row = rows - 1; 0 <= row; row--) {
94 /* Time (ROWS) */
95 for (let col = cols - 1; 1 <= col; col--) {
96 /* Time (COLS) */
97 if (!isZero(matrix, row, col)) continue;
98
99 matrix[row][col] = 0;
100 }
101
102 if (isColZero) matrix[row][0] = 0;
103 }
104};
105
106var isZero = (matrix, row, col) => {
107 const [rowLeftEdge, colTopEdge] = [matrix[row][0], matrix[0][col]];

Callers 1

setZeroesFunction · 0.85

Calls 1

isZeroFunction · 0.85

Tested by

no test coverage detected