Skip to content

Commit a1b9ddf

Browse files
committed
feat: add ts solution to lc problem: No.1380
No.1380.Lucky Numbers in a Matrix
1 parent c46188a commit a1b9ddf

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

solution/1300-1399/1380.Lucky Numbers in a Matrix/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,34 @@ func max(a, b int) int {
167167
}
168168
```
169169

170+
### **TypeScript**
171+
172+
```ts
173+
function luckyNumbers(matrix: number[][]): number[] {
174+
const m = matrix.length;
175+
const n = matrix[0].length;
176+
const col = new Array(n).fill(0);
177+
const res = [];
178+
for (let j = 0; j < n; j++) {
179+
for (let i = 0; i < m; i++) {
180+
col[j] = Math.max(col[j], matrix[i][j]);
181+
}
182+
}
183+
for (let x = 0; x < m; x++) {
184+
let i = 0;
185+
for (let y = 1; y < n; y++) {
186+
if (matrix[x][i] > matrix[x][y]) {
187+
i = y;
188+
}
189+
}
190+
if (matrix[x][i] === col[i]) {
191+
res.push(col[i]);
192+
}
193+
}
194+
return res;
195+
}
196+
```
197+
170198
### **Rust**
171199

172200
```rust

solution/1300-1399/1380.Lucky Numbers in a Matrix/README_EN.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,34 @@ func max(a, b int) int {
153153
}
154154
```
155155

156+
### **TypeScript**
157+
158+
```ts
159+
function luckyNumbers(matrix: number[][]): number[] {
160+
const m = matrix.length;
161+
const n = matrix[0].length;
162+
const col = new Array(n).fill(0);
163+
const res = [];
164+
for (let j = 0; j < n; j++) {
165+
for (let i = 0; i < m; i++) {
166+
col[j] = Math.max(col[j], matrix[i][j]);
167+
}
168+
}
169+
for (let x = 0; x < m; x++) {
170+
let i = 0;
171+
for (let y = 1; y < n; y++) {
172+
if (matrix[x][i] > matrix[x][y]) {
173+
i = y;
174+
}
175+
}
176+
if (matrix[x][i] === col[i]) {
177+
res.push(col[i]);
178+
}
179+
}
180+
return res;
181+
}
182+
```
183+
156184
### **Rust**
157185

158186
```rust
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function luckyNumbers(matrix: number[][]): number[] {
2+
const m = matrix.length;
3+
const n = matrix[0].length;
4+
const col = new Array(n).fill(0);
5+
const res = [];
6+
for (let j = 0; j < n; j++) {
7+
for (let i = 0; i < m; i++) {
8+
col[j] = Math.max(col[j], matrix[i][j]);
9+
}
10+
}
11+
for (let x = 0; x < m; x++) {
12+
let i = 0;
13+
for (let y = 1; y < n; y++) {
14+
if (matrix[x][i] > matrix[x][y]) {
15+
i = y;
16+
}
17+
}
18+
if (matrix[x][i] === col[i]) {
19+
res.push(col[i]);
20+
}
21+
}
22+
return res;
23+
}

0 commit comments

Comments
 (0)