
commands 순회UP, RIGHT, DOWN, LEFT 명령에 따른 X, Y 좌표 변경N * Y + X의 점화식이 Array[Y][X]의 값이므로, 결괏값 반환function finalPositionOfSnake(n: number, commands: string[]): number {
let [y, x] = [0, 0]
for(const command of commands) {
switch(command) {
case 'UP':
y--
break
case 'RIGHT':
x++
break
case 'DOWN':
y++
break
case 'LEFT':
x--
break
}
}
return y * n + x
};