-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path예산.java
More file actions
29 lines (26 loc) · 725 Bytes
/
예산.java
File metadata and controls
29 lines (26 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 예산 (https://school.programmers.co.kr/learn/courses/30/lessons/12982)
import java.util.Arrays;
class Solution {
public int solution(int[] d, int budget) {
int answer = d.length;
int sum = Arrays.stream(d).sum();
Arrays.sort(d);
for (int i = d.length - 1; i >= 0; i--, answer--) {
if (sum <= budget)
break;
sum -= d[i];
}
return answer;
}
public int solution2(int[] d, int budget) {
int answer = 0;
Arrays.sort(d);
for (int i = 0; i < d.length; i++) {
budget -= d[i];
if (budget < 0)
break;
answer++;
}
return answer;
}
}