/** * @param {number[][]}grid * @return {number} */ var countNegatives = function (grid) { let i = 0, j = 0, res = 0, m = grid.length, n = grid[0].length; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (grid[i][j] < 0) { res += (m - i) * (n - j); n = j; break; } } } return res; };