-
728x90
[ 풀이 방법 ]
- 인쇄 중요도가 높은 문서부터 차례대로 뽑는다. => 우선순위 큐
- queue에서 하나씩 꺼낼때마다 priorities[i]에서 그 값을 찾고 answer을 증가시킨다.
이때, i가 만약 location이라면 answer을 리턴한다.[ 전체 코드 ]
import java.util.*;class Solution {public int solution(int[] priorities, int location) {int answer = 1;PriorityQueue<Integer> queue = new PriorityQueue<Integer>(Comparator.reverseOrder());for(int n : priorities)queue.offer(n);while(!queue.isEmpty()) {for(int i = 0; i < priorities.length; i++) {if(queue.peek() == priorities[i]) {if(location == i)return answer;answer++;queue.poll();}}}return answer;}}데롱디롱희희.. (๑′ᴗ‵๑)
'알고리즘 풀이 > 프로그래머스' 카테고리의 다른 글
[level2] 프로그래머스 - 더 맵게(JAVA) (0) 2021.09.18 [level3] 프로그래머스 - 베스트앨범(JAVA) (1) 2021.09.17 [level3] 프로그래머스 - 가장 먼 노드(JAVA) (0) 2021.09.17 [level3] 프로그래머스 - 순위(JAVA) (0) 2021.09.17 [level2] 프로그래머스 - 위장(JAVA) (0) 2021.09.15