알고리즘 풀이/프로그래머스
[프로그래머스][Java] 프린터
배게
2019. 3. 20. 04:26
728x90
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import java.util.*; public class Paper{ int num; int importance; public Paper ( int num, int importance ){ this.num = num; this.importance = importance; } } class Solution { public int solution(int[] priorities, int location) { LinkedList<Paper> pp = new LinkedList<Paper>(); int n = priorities.length; for(int i=0; i<n; i++){ pp.add(new Paper(i+1, priorities[i])); } for(int i=0; i<n; i++){ System.out.println(pp.get(i).num + " " +pp.get(i).importance); } int answer = 1; while(pp.size()>1){ Paper firstPaper = pp.getFirst(); for(int i=1;i<pp.size(); i++){ if(firstPaper.importance < pp.get(i).importance){ pp.add(firstPaper); pp.removeFirst(); break; } if(i== pp.size()-1) { if(firstPaper.num==location+1) return answer; pp.removeFirst(); answer++; } } } return answer; } } |
참고 : https://developerdk.tistory.com/15