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)


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