Skip to content

Commit 33b275f

Browse files
authored
20251103 (#25)
add: 봉우리
1 parent be0a52d commit 33b275f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function solution(arr) {
2+
let answer = 0;
3+
const n = arr.length;
4+
const dx = [-1, 1, 0, 0];
5+
const dy = [0, 0, -1, 1];
6+
7+
for (let i = 0; i < n; i++) {
8+
for (let j = 0; j < n; j++) {
9+
let flag = 1;
10+
11+
for (let k = 0; k < 4; k++) {
12+
const nx = i + dx[k];
13+
const ny = j + dy[k];
14+
const current = arr[i][j];
15+
const neighbor = arr[nx][ny];
16+
17+
if (nx >= 0 && nx < n && ny >= 0 && ny < n) {
18+
if (neighbor >= current) {
19+
flag = 0;
20+
break;
21+
}
22+
}
23+
}
24+
if (flag) answer++;
25+
}
26+
}
27+
return answer;
28+
}
29+
30+
const input = [
31+
[5, 3, 7, 2, 3],
32+
[3, 7, 1, 6, 1],
33+
[7, 2, 5, 3, 4],
34+
[4, 3, 6, 4, 1],
35+
[8, 7, 3, 5, 2],
36+
];
37+
console.log(solution(input));

0 commit comments

Comments
 (0)