Skip to content

Commit a59da3c

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 5fc1bb8 + 3f8921a commit a59da3c

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package Week2.공통.명예의전당_1;
2+
3+
import java.util.PriorityQueue;
4+
5+
public class suhyun {
6+
7+
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
8+
public int[] solution(int k, int[] score) {
9+
int[] answer = new int[score.length];
10+
11+
for(int i=0; i<score.length; i++){
12+
if(pq.size() >= k){
13+
if(score[i] > pq.peek()){
14+
pq.poll();
15+
}
16+
}
17+
18+
if(pq.size() < k){
19+
pq.offer(score[i]);
20+
}
21+
22+
answer[i] = pq.peek();
23+
}
24+
25+
return answer;
26+
}
27+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import heapq
2+
def solution(k, score):
3+
answer = []
4+
heap = []
5+
6+
for current_score in score:
7+
if len(heap) >= k:
8+
if current_score > heap[0]:
9+
heapq.heappop(heap)
10+
11+
if len(heap) < k:
12+
heapq.heappush(heap, current_score)
13+
14+
answer.append(heap[0])
15+
16+
return answer
17+
18+
score = [10, 100, 20, 150, 1, 100, 200]
19+
print(solution(3, score))
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import heapq
2+
def solution(k, score):
3+
answer = []
4+
heap = []
5+
6+
for current_score in score:
7+
if len(heap) >= k:
8+
if current_score > heap[0]:
9+
heapq.heappop(heap)
10+
11+
if len(heap) < k:
12+
heapq.heappush(heap, current_score)
13+
14+
answer.append(heap[0])
15+
return answer
16+
17+
score = [10, 100, 20, 150, 1, 100, 200]
18+
print(solution(3, score))

Week2/공통/명예의전당_1/test.java

-4
This file was deleted.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def solution(s):
2+
answer = 0
3+
cnt1, cnt2 = 0, 0
4+
5+
for i in s:
6+
if cnt1 == cnt2:
7+
k = i
8+
answer += 1
9+
10+
if k == i:
11+
cnt1 += 1
12+
else:
13+
cnt2 += 1
14+
return answer
15+
16+
print(solution("abracadabra"))
17+
# print(solution("aaabbaccccabba"))

0 commit comments

Comments
 (0)