목록lv.1 (2)
밍쎄의 코딩공간
그래프 탐색 문제이다. 푸는 과정 속에 어려움을 겪어 밑에 분의 코드를 참고하였다. // 2차원 배열을 벗어나지 않으면서 X가 아니면 재귀 호출 이 부분을 구현하는 것이 매우 미흡하였다. import java.util.*; class Solution { static int startX; static int startY; public int[] solution(String[] park, String[] routes) { int[] answer = new int[2]; // 동서남북 이동할 좌표 map에 삽입 Map map = new HashMap(); map.put("N", new int[]{-1, 0}); map.put("E", new int[]{0, 1}); map.put("S", new int[]{1..
import java.util.HashSet; class Solution { public int solution(int n, int[] lost, int[] reserve) { int answer = 0; HashSet resSet = new HashSet(); HashSet loSet = new HashSet(); for(int i: reserve) { resSet.add(i); } for(int i: lost) { if(resSet.contains(i)) { resSet.remove(i); } else { loSet.add(i); } } for(int i: resSet) { if(loSet.contains(i-1)) { loSet.remove(i - 1); } else if(loSet.contains..