leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1351.cpp (390B)


0 class Solution { 1 public: 2 int countNegatives(vector<vector<int>> &grid) { 3 int n = grid.size(), m = grid[0].size(), res = 0; 4 int i = n - 1, j = 0, cnt = 0; 5 while (i >= 0 && j < m) { 6 if (grid[i][j] < 0) { 7 res += m - j; 8 i--; 9 } else { 10 j++; 11 } 12 } 13 return res; 14 } 15 };