알고리즘 문제/[프로그래머스] Lv2
방문 길이
Muscardinus
2022. 4. 8. 19:12
728x90
https://programmers.co.kr/learn/courses/30/lessons/49994
코딩테스트 연습 - 방문 길이
programmers.co.kr
function solution(dirs) {
let cur = [0, 0];
const dObj = {
"U": [-1, 0],
"D": [1, 0],
"L": [0, -1],
"R": [0, 1],
};
const track = new Set();
for (let dir of dirs) {
const ny = cur[0] + dObj[dir][0];
const nx = cur[1] + dObj[dir][1];
if (ny > 5 || ny < -5 || nx > 5 || nx < -5) continue;
track.add(`${cur[0]}${cur[1]}${ny}${nx}`);
track.add(`${ny}${nx}${cur[0]}${cur[1]}`);
cur = [ny, nx];
}
return track.size / 2;
}
풀이해설
https://after-newmoon.tistory.com/92
[프로그래머스] 방문길이 /JavaScript
https://programmers.co.kr/learn/courses/30/lessons/49994 코딩테스트 연습 - 방문 길이 programmers.co.kr function solution(dirs) { const move = { U : [0, 1], D : [0, -1], L : [-1, 0], R : [1,0]} ; le..
after-newmoon.tistory.com
728x90