본문 바로가기
Problem Solving

[프로그래머스] L1 예산

by JYHAN 2020. 12. 19.

순서도

[프로그래머스] L1 예산

[풀이]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.util.*;
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]){
                budget -= d[i];
                answer++;
            }
        }
        return answer;
    }
}
cs

댓글