프로그래머스 - 게임 맵 최단거리 - java


프로그래머스 - 게임 맵 최단거리 - java

2차원 배열 미로에서 최단거리(경로) 찾기 문제 bfs로 풀되, 1. 각 경로에 현재 좌표(y,x)와 현재까지 이동한 칸 수를 저장해야 한다. (queue의 원소가 Integer[3]인 이유) 2. 어떤 칸에 도달했다면, 그 칸에 도달한 것을 표시하여야 한다. 그래야 루프를 피할 수 있다. (2차원 배열 visited가 있는 이유) import java.util.*; class Solution { int mMinStepCount = 0; int mHeight = 0; int mWidth = 0; boolean DEBUG = false; void log (String s){ if (DEBUG){ System.out.println(s); } } public int solution(int[][] maps) { int answer = 0; mHeight = maps.length; mWidth = maps[0].length; mMinStepCount = (mHeight+1)*(mWidth+1...



원문링크 : 프로그래머스 - 게임 맵 최단거리 - java