Skip to content

Commit 1379124

Browse files
add 1351
1 parent df4511d commit 1379124

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1351|[Count Negative Numbers in a Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1351.java) | |Easy|Array, Binary Search|
1112
|1349|[Maximum Students Taking Exam](https://leetcode.com/problems/maximum-students-taking-exam/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1349.java) | |Hard|Dynamic Programming|
1213
|1348|[Tweet Counts Per Frequency](https://leetcode.com/problems/tweet-counts-per-frequency/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1348.java) | |Medium|Design|
1314
|1347|[Minimum Number of Steps to Make Two Strings Anagram](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1347.java) | |Easy|String|
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 1351. Count Negative Numbers in a Sorted Matrix
5+
*
6+
* Given a m * n matrix grid which is sorted in non-increasing order both row-wise and column-wise.
7+
* Return the number of negative numbers in grid.
8+
*
9+
* Example 1:
10+
* Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
11+
* Output: 8
12+
* Explanation: There are 8 negatives number in the matrix.
13+
*
14+
* Example 2:
15+
* Input: grid = [[3,2],[1,0]]
16+
* Output: 0
17+
*
18+
* Example 3:
19+
* Input: grid = [[1,-1],[-1,-1]]
20+
* Output: 3
21+
*
22+
* Example 4:
23+
* Input: grid = [[-1]]
24+
* Output: 1
25+
*
26+
* Constraints:
27+
* m == grid.length
28+
* n == grid[i].length
29+
* 1 <= m, n <= 100
30+
* -100 <= grid[i][j] <= 100
31+
* */
32+
public class _1351 {
33+
public static class Solution1 {
34+
public int countNegatives(int[][] grid) {
35+
int count = 0;
36+
for (int[] row : grid) {
37+
for (int v : row) {
38+
if (v < 0) {
39+
count++;
40+
}
41+
}
42+
}
43+
return count;
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)