Niloy007

Count Negative Numbers in a Sorted Matrix

Mar 14th, 2021
642
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int countNegatives(vector<vector<int>>& grid) {
  4.         int ans = 0;
  5.         for (auto u : grid) {
  6.             reverse(u.begin(), u.end());
  7.             ans += lower_bound(u.begin(), u.end(), 0) - u.begin();
  8.         }
  9.         return ans;
  10.     }
  11. };
RAW Paste Data