손코딩

[프로그래머스] 예산 본문

Java

[프로그래머스] 예산

활시현 2021. 1. 28. 09:16
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;
    }
}