18 lines
374 B
Go
18 lines
374 B
Go
// Package q1351 implements a solution for https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/
|
|
package q1351
|
|
|
|
func countNegatives(grid [][]int) int {
|
|
w := len(grid[0])
|
|
count := 0
|
|
|
|
countRow := 0
|
|
for r := range grid {
|
|
for countRow < w && (grid[r][w-countRow-1] < 0) {
|
|
countRow++
|
|
}
|
|
count += countRow
|
|
}
|
|
return count
|
|
}
|
|
|
|
var _ = countNegatives
|