손코딩
[프로그래머스] 예산 본문
728x90
728x90
import java.util.Arrays;
class Solution {
public int solution(int[] d, int budget) {
int answer = 0;
int total = 0;
Arrays.sort(d);
for(int i=0; i<d.length; i++){
if(total + d[i] > budget){
break;
}
total += d[i];
answer++;
}
return answer;
}
}
'Java' 카테고리의 다른 글
[프로그래머스] 완주하지 못한 선수 (0) | 2021.01.28 |
---|---|
[프로그래머스] x만큼 간격이 있는 n개의 숫자 (0) | 2021.01.28 |
[프로그래머스] 하샤드수 (0) | 2021.01.28 |
[프로그래머스] 콜라츠 추측 (0) | 2021.01.27 |
[프로그래머스] 짝수와 홀수 (0) | 2021.01.27 |