1. λ¬Έμ μ λνμ¬ π¦
(1) 쑰건 λΆμ π
- κ° νλ‘μΈμ€λ 무쑰건 μ°μ μμκ° λμ μμΌλ‘ μ€νλλ€.
- μ΄λ μΈμλ‘ μ£Όμ΄μ§ μ«μκ° μλ λκΈ° ν μ μμΉμΈ νλ‘μΈμ€κ° μ€νλλ μμλ μΈμ μΌκΉ?
2. μ½λκ° λμ€κΈ°κΉμ§ π οΈ
KEY WORD
: ν νμ©
- νλ‘μΈμ€μ μ€ν μ°μ μμκ° λμ κ²λΆν° λ΄λ¦Όμ°¨μν μ°μ μμ ν λ§λ€κΈ°
(μ°μ μμ νλ 'μ€ν λκΈ° μ€μΈ νλ‘μΈμ€ μ€ μ°μ μμκ° λμ μ' μ΄λ€. - νλ‘μΈμ€μ μλ μμΉλ₯Ό λ΄μ μΌλ° ν λ§λ€κΈ°
- μ°μ μμ νμ peek()μ μ°μ μμ == νλ‘μΈμ€μ poll()μ μ°μ μμμ΄λ©΄, νμ¬ νλ‘μΈμ€ μ€νν΄λ λλ€. μ΄λ ν΄λΉ νλ‘μΈμ€λ μ΄λ―Έ μ€ν ν μ’ λ£νμΌλ―λ‘, μ°μ μμ νμμλ μ κ±°νλ€.
- λ§μ½ 2λ²μ΄ μλλ©΄ poll()ν νλ‘μΈμ€λ₯Ό λ€μ μΌλ° ν 꼬리μ λ£λλ€.
(1) μκ°λ³΅μ‘λ λΆμ β³
- μκ°λ³΅μ‘λμ λΆμμ΄ νμ μλ λ¬Έμ μλ€.
3. μ½λ π
import java.util.*;
class Solution {
static class Ps {
int p; // μ°μ μμ
int ol; // μλ λ²νΈ
public Ps(int p, int ol) {
this.p = p;
this.ol = ol;
}
}
public int solution(int[] priorities, int location) {
PriorityQueue<Ps> pg = new PriorityQueue<>((p1,p2) -> (p2.p - p1.p));
ArrayDeque<Ps> os = new ArrayDeque<>();
for(int i = 0; i < priorities.length; i++){
Ps now = new Ps(priorities[i], i);
pg.add(now);
os.add(now);
}
int num = 0;
while(!os.isEmpty()){
Ps top = pg.peek();
Ps now = os.poll();
if(top.p == now.p) {
pg.poll();
num++;
if(now.ol == location) return num;
}else{
os.add(now);
}
}
return num;
}
}
4. νΈλ¬λΈ μν or λ°°μ΄ μ π
0