You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constisVisited=Array.from({length: N},()=>Array(N).fill(false));// 방문 기록 배열
17
-
//new array 방식으로는 불가한가?
18
-
constcurrentPos=[[0,0]];//DFS를 탐색을 시작할 좌표를 담는 초기 스택
19
-
//왜 currentPos은 2차원 배열이여야 하는가?
20
-
letanswer=false;
21
-
22
-
//왜 [x,y]가 아닌 y,x인가?
23
-
/**
24
-
* const [y, x] = currentPos.pop()에서 y와 x는 순서대로 y축(세로)과 x축(가로)의 좌표를 의미합니다. 좌표를 다룰 때 보통 (y, x) 형태로 사용합니다. 이 구조는 2차원 배열에서 먼저 행(row)인 y가 나오고, 그다음에 열(column)인 x가 나오는 방식이다.
25
-
*/
26
-
while(currentPos.length>0){
27
-
const[y,x]=currentPos.pop();//currentPos의 마지막 요소 pop -> 구조 분해 할당으로 pop이 반환한 값을 받는다.
28
-
console.log(`현재 위치: [${y}, ${x}]`);
29
-
constcurrentMov=arr[y][x];//해당 x,y위치 값
30
-
//currentMov 가 움직이는 칸의 갯수
31
-
//단, y,x 의 위 이동 기준은
32
-
console.log(`현재 값: ${currentMov}`);
33
-
34
-
if(currentMov===-1){// 종료 조건
35
-
console.log('목표에 도착');
36
-
answer=true;
37
-
break;
38
-
}
39
-
40
-
// y축 방향으로 이동
41
-
if(y+currentMov<N&&!isVisited[y+currentMov][x]){
42
-
//isVisited[y + currentMov][x] 부분이 true인지 false인지 확인하는 조건문이다.
0 commit comments