We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a53f1e1 commit 8dbe4a7Copy full SHA for 8dbe4a7
Programmers/Level2/JY_뒤에_있는_큰_수_찾기.java
@@ -0,0 +1,43 @@
1
+import java.util.*;
2
+
3
+class Solution {
4
5
+ static class State implements Comparable<State>{
6
+ int num, idx;
7
+ public State(int num, int idx) {
8
+ this.num = num;
9
+ this.idx = idx;
10
+ }
11
+ @Override
12
+ public int compareTo(State other){
13
+ if(this.num == other.num){
14
+ return this.idx-other.idx;
15
16
+ return this.num - other.num;
17
18
19
+ public String toString(){
20
+ return "n:"+this.num+" i:"+this.idx;
21
22
23
24
+ public int[] solution(int[] numbers) {
25
+ int N = numbers.length;
26
+ int[] answer = new int[N];
27
+ for(int i=0; i<N; i++){
28
+ answer[i] = -1;
29
30
31
+ PriorityQueue<State> pq = new PriorityQueue<>();
32
33
+ int val = numbers[i];
34
+ while(!pq.isEmpty() && pq.peek().num < val){
35
+ State pre = pq.poll();
36
+ answer[pre.idx] = val;
37
38
+ pq.add(new State(val, i));
39
40
41
+ return answer;
42
43
+}
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments