count-negative-numbers-in-a-matrix.dart (567B)
1 //Given a grid of columnally sorted values return the number 2 //of negative values. This is a brute force solution, but is also 3 //nearly as good as an opomized one. 4 5 //Ex input: 6 //4 0 -3 7 //3 -1 8 //2 -2 9 10 class Solution { 11 int countNegatives(List<List<int>> grid) { 12 int count = 0; 13 for(int i = grid.length - 1; i >= 0 ; --i){ 14 for(int x = grid[i].length - 1; x >= 0 ; --x){ 15 if(grid[i][x] < 0){ 16 count += 1; 17 continue; 18 } 19 break; 20 } 21 } 22 return count; 23 } 24 }