Skip to content

Commit 64ee05e

Browse files
authored
Create 1380-lucky-numbers-in-a-matrix.js
1 parent e32d4a6 commit 64ee05e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

1380-lucky-numbers-in-a-matrix.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @param {number[][]} matrix
3+
* @return {number[]}
4+
*/
5+
const luckyNumbers = function(matrix) {
6+
const m = matrix.length, n = matrix[0].length
7+
const res = []
8+
for(let i = 0; i < m; i++) {
9+
let tmp = [i, 0, matrix[i][0]]
10+
for(let j = 1; j < n; j++) {
11+
if(matrix[i][j] < tmp[2]) {
12+
tmp = [i, j, matrix[i][j]]
13+
}
14+
}
15+
res.push(tmp)
16+
}
17+
18+
const ans = []
19+
for(let [r, c, v] of res) {
20+
let found = false
21+
for(let i = 0; i < m; i++) {
22+
if(i !== r && matrix[i][c] > v) {
23+
found = true
24+
break
25+
}
26+
}
27+
28+
if(found === false) ans.push(v)
29+
}
30+
31+
return ans
32+
};

0 commit comments

Comments
 (0)