1351. Count Negative Numbers in a Sorted Matrix Easy
1/**
2 * [1351] Count Negative Numbers in a Sorted Matrix
3 *
4 * Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.
5 *
6 * Example 1:
7 *
8 * Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
9 * Output: 8
10 * Explanation: There are 8 negatives number in the matrix.
11 *
12 * Example 2:
13 *
14 * Input: grid = [[3,2],[1,0]]
15 * Output: 0
16 *
17 *
18 * Constraints:
19 *
20 * m == grid.length
21 * n == grid[i].length
22 * 1 <= m, n <= 100
23 * -100 <= grid[i][j] <= 100
24 *
25 *
26 * Follow up: Could you find an O(n + m) solution?
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/
31// discuss: https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn count_negatives(grid: Vec<Vec<i32>>) -> i32 {
37 0
38 }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_1351() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.