728x90
프로그래머스 1단계
예산
https://programmers.co.kr/learn/challenges
문제 설명
풀이
import java.util.Arrays;
class Solution {
public int solution(int[] d, int budget) {
int answer = 0;
Arrays.sort(d);
for (int i = 0; i<d.length; i++) {
if (budget-d[i] >= 0) {
budget-=d[i];
answer++;
} else {
break;
}
}
return answer;
}
}
728x90
'알고리즘 > 프로그래머스 1단계' 카테고리의 다른 글
[프로그래머스] 문자열 내 마음대로 정렬하기 (0) | 2022.04.25 |
---|---|
[프로그래머스] 나누어 떨어지는 숫자 배열 (0) | 2022.04.25 |
[프로그래머스] 모의고사 (0) | 2022.04.24 |
[프로그래머스] 직사각형 별찍기 (0) | 2022.04.24 |
[프로그래머스] 자연수 뒤집어 배열로 만들기 (0) | 2022.04.24 |
댓글