회의실 만남(구현부분)과 현관문 출입순서(자료구조) 질문드립니다.
public int[] solution(int[] enter, int[] exit){ int totalWorker = enter.length; int[] answer = new int[totalWorker]; // 나갈사람들 Deque exitWorkers = new LinkedList(); for (int exitWorker : exit) { exitWorkers.offer(exitWorker); } // 만난 사람들을 검증하는 배열 boolean[][] hasMeet = new boolean[totalWorker + 1][totalWorker + 1]; for (int self = 0; self workersInMeetingRoom = new HashSet(); while (!exitWorkers.isEmpty()) { for (int enterWorker : enter) { workersInMeetingRoom.add(enterWorker); for (int workerInMeetingRoom : workersInMeetingRoom) { if (!hasMeet[workerInMeetingRoom][enterWorker]) { answer[enterWorker - 1]++; answer[workerInMeetingRoom - 1]++; hasMeet[workerInMeetingRoom][enterWorker] = true; hasMeet[enterWorker][workerInMeetingRoom] = true; } } while (workersInMeetingRoom.contains(exitWorkers.peek())) { int exitWorker = exitWorkers.poll(); workersInMeetingRoom.remove(exitWorker); } } } return answer; }저는 Set과 Queue(Deque)을 이용해서 풀어봤습니다. 컴파일 시 출력은 일치하지만 좋은 코드인지는 잘 모르겠습니다!