Skip to content

Commit 5749453

Browse files
authored
feat: add typescript solution to lc problem: No.1351.Count Negative Numbers in a Sorted Matrix (doocs#511)
1 parent 0f41fea commit 5749453

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

solution/1300-1399/1351.Count Negative Numbers in a Sorted Matrix/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ class Solution {
108108
}
109109
```
110110

111+
### **TypeScript**
112+
113+
```ts
114+
function countNegatives(grid: number[][]): number {
115+
let m = grid.length, n = grid[0].length;
116+
let i = 0, j = n - 1;
117+
let ans = 0;
118+
while (i < m && j > -1) {
119+
let cur = grid[i][j];
120+
if (cur < 0) {
121+
j--;
122+
ans += (m - i);
123+
} else {
124+
i++;
125+
}
126+
}
127+
return ans;
128+
};
129+
```
130+
111131
### **C++**
112132

113133
```cpp

solution/1300-1399/1351.Count Negative Numbers in a Sorted Matrix/README_EN.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ class Solution {
8989
}
9090
```
9191

92+
### **TypeScript**
93+
94+
```ts
95+
function countNegatives(grid: number[][]): number {
96+
let m = grid.length, n = grid[0].length;
97+
let i = 0, j = n - 1;
98+
let ans = 0;
99+
while (i < m && j > -1) {
100+
let cur = grid[i][j];
101+
if (cur < 0) {
102+
j--;
103+
ans += (m - i);
104+
} else {
105+
i++;
106+
}
107+
}
108+
return ans;
109+
};
110+
```
111+
92112
### **C++**
93113

94114
```cpp
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function countNegatives(grid: number[][]): number {
2+
let m = grid.length, n = grid[0].length;
3+
let i = 0, j = n - 1;
4+
let ans = 0;
5+
while (i < m && j > -1) {
6+
let cur = grid[i][j];
7+
if (cur < 0) {
8+
j--;
9+
ans += (m - i);
10+
} else {
11+
i++;
12+
}
13+
}
14+
return ans;
15+
};

0 commit comments

Comments
 (0)