Skip to content

Commit 3ed157c

Browse files
committed
공원 산책 / 중급
1 parent ad8b945 commit 3ed157c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function solution(park, routes) {
2+
let queue = [...routes];
3+
4+
let [x, y] = park.map((s, i) => [s.indexOf('S'), i]).find(v => v[0] > -1);
5+
6+
let [h, w] = [park.length, park[0].length];
7+
8+
while(queue.length) {
9+
let [d, n] = queue.shift().split(' ');
10+
let [nx, ny] = [x, y];
11+
let go = true;
12+
13+
for(let i = 0; i < n; i++) {
14+
if(d === 'N') ny--;
15+
if(d === 'S') ny++;
16+
if(d === 'W') nx--;
17+
if(d === 'E') nx++;
18+
19+
if(ny < 0 || ny >= h || nx < 0 || nx >= w || park[ny][nx] === 'X') {
20+
go = false;
21+
break;
22+
}
23+
}
24+
25+
if(go) [x, y] = [nx, ny];
26+
}
27+
28+
return [y, x];
29+
}

0 commit comments

Comments
 (0)