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

Function setEdgesToZero

javascript/0073-set-matrix-zeroes.js:74–88  ·  view source on GitHub ↗
(matrix)

Source from the content-addressed store, hash-verified

72 matrix.some((row) => row[0] === 0); /* Time O(ROWS) */
73
74var setEdgesToZero = (matrix) => {
75 const [rows, cols] = [matrix.length, matrix[0].length];
76
77 for (let row = 0; row < rows; row++) {
78 /* Time (ROWS) */
79 for (let col = 1; col < cols; col++) {
80 /* Time (COLS) */
81 const canSet = matrix[row][col] === 0;
82 if (!canSet) continue;
83
84 matrix[row][0] = 0;
85 matrix[0][col] = 0;
86 }
87 }
88};
89
90var setCellsToZero = (matrix, isColZero) => {
91 const [rows, cols] = [matrix.length, matrix[0].length];

Callers 1

setZeroesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected