[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] LV.2 ํ”„๋ฆฐํ„ฐ (์ž๋ฐ” java)

 

1. ๋ฌธ์ œ : https://school.programmers.co.kr/learn/courses/30/lessons/42587

 

2. ํ’€์ด

location ์ด๋™ํ•ด๊ฐ€๋ฉด์„œ ๊ฐ’ ๋น„๊ตํ›„ pop

 

3. ์ฝ”๋“œ

import java.util.*;

class Solution {
    public int solution(int[] priorities, int location) {
        int answer = 0;
        List<Integer> li = new ArrayList<Integer>();
        
        for(int i=0; i<priorities.length; i++){
            li.add(priorities[i]);
        }

        while(true){
            int pri = li.get(0);
            boolean ch = false;
            
            for(int i=0; i<li.size(); i++){
                if(pri<li.get(i)){
                    ch = true;
                    break;
                }
            }
            
            if(ch==true){
                li.remove(0);
                li.add(pri);
                if(location == 0) location = li.size()-1;
                else location--;
                ch = false;
            }
            else{
                answer++;
                li.remove(0);
                if(location == 0) break;
                else location--;
            }
        }
        return answer;
    }
}
  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ