commit faf1dd71b3b096de81f31f9fb638a854729442d8 parent d9d54c37c054179b567850de539b9ad876825d4e Author: AndrewLockVI <andrewlaack1@gmail.com> Date: Wed, 7 Jun 2023 20:46:22 -0500 Completed count negative numbers in a matrix using dart Diffstat:
| A | count-negative-numbers-in-a-matrix/count-negative-numbers-in-a-matrix.dart | | | 24 | ++++++++++++++++++++++++ |
1 file changed, 24 insertions(+), 0 deletions(-)
diff --git a/count-negative-numbers-in-a-matrix/count-negative-numbers-in-a-matrix.dart b/count-negative-numbers-in-a-matrix/count-negative-numbers-in-a-matrix.dart @@ -0,0 +1,24 @@ +//Given a grid of columnally sorted values return the number +//of negative values. This is a brute force solution, but is also +//nearly as good as an opomized one. + +//Ex input: +//4 0 -3 +//3 -1 +//2 -2 + +class Solution { + int countNegatives(List<List<int>> grid) { + int count = 0; + for(int i = grid.length - 1; i >= 0 ; --i){ + for(int x = grid[i].length - 1; x >= 0 ; --x){ + if(grid[i][x] < 0){ + count += 1; + continue; + } + break; + } + } + return count; + } +}