[ํ๋ก๊ทธ๋๋จธ์ค] 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;
}
}
'๐ป Coding Problems Solving > Stack | Queue' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ 1863] ์ค์นด์ด๋ผ์ธ ์ฌ์ด๊ฑฐ (0) | 2023.06.07 |
---|---|
[BOJ 11000] ๊ฐ์์ค ๋ฐฐ์ (0) | 2023.05.25 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ฌ๋ฐ๋ฅธ ๊ดํธ (์๋ฐ java) (0) | 2022.11.25 |
[BOJ 2504] ๊ดํธ์ ๊ฐ (0) | 2022.06.26 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๋ค๋ฆฌ๋ฅผ ์ง๋๋ ํธ๋ญ (0) | 2022.04.15 |
์ต๊ทผ๋๊ธ