https://school.programmers.co.kr/learn/courses/30/lessons/42885?language=java
1. ๋ฌธ์
2. ํ์ด
3. ์ฝ๋
import java.io.*;
import java.util.*;
class Solution {
public int solution(int[] people, int limit) {
int ans = 0;
int left = 0;
int right = people.length-1;
//๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ
PriorityQueue<Integer> pq = new PriorityQueue<> ((o1,o2)->o2-o1);
for (int i : people) {
pq.offer(i);
}
Integer[] pp = new Integer[people.length];
int i=0;
while (!pq.isEmpty()) {
pp[i++] = pq.poll();
}
while (left <= right) {
if (left == right) {
ans++;
break;
}
int sum = pp[left] + pp[right];
if (sum > limit) {
left++;
}
else {
left++;
right--;
}
ans++;
}
return ans;
}
}
4. ์ฌ๋ด
'Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] ์ด์ค์ฐ์ ์์ํ - Java (0) | 2023.08.17 |
---|---|
[Programmers] ์ ํ์ ์๊ฐ์ด๋ - Java (0) | 2023.08.11 |
[Programmers] ์นดํซ - Java (0) | 2023.07.09 |
[Programmers] ์์ด ๋๋ง์๊ธฐ - Java (0) | 2023.01.09 |
[Programmers] ๊ทค๊ณ ๋ฅด๊ธฐ - Java (0) | 2023.01.04 |