Skip to content

Commit 12b23b2

Browse files
Added solution
1 parent 9698af4 commit 12b23b2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

count_negative_in_2d.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int countNegatives(vector<vector<int>>& grid) {
4+
5+
if(grid.size() == 0) return 0;
6+
int cn = 0;
7+
8+
for(int i=grid.size()-1; i>=0; i--){
9+
for(int j=grid[i].size()-1; j>=0; j--){
10+
if(grid[i][j] < 0)
11+
cn++;
12+
if(grid[i][j] >= 0)
13+
break;
14+
}
15+
}
16+
return cn;
17+
}
18+
};

0 commit comments

Comments
 (0)