본문 바로가기
알고리즘

[Java]프로그래머스 프린터

by irerin07 2019. 4. 15.
728x90

```

import java.util.LinkedList;
import java.util.Queue;

class Solution {
    public int solution(int[] priorities, int location) {
        
        Queue q  =new LinkedList<>();
        for(int p:priorities) {
            q.offer(p);
        }
        
        int count=0;
        
        while(!q.isEmpty()) {
            int item = q.poll();
            
            boolean check = true;
            for(int s:q) {
                if(item<s) {
                    check=false;
                }
            }
            
            if(check) {
                count++;
                if(location==0) 
                    return count;
            }else {
                q.offer(item);
            }
            
            location--;
            if(location<0)location+=q.size();
        }
        return count;
    }
}

```

728x90