Advertisement
Niloy007

Count Negative Numbers in a Sorted Matrix

Mar 14th, 2021
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  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. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement