본문 바로가기
알고리즘/프로그래머스 1단계

[프로그래머스] 예산

by lanuarius19 2022. 4. 24.
728x90

 

프로그래머스 1단계
예산

https://programmers.co.kr/learn/challenges

 

문제 설명

 

예산1
예산2

 

 

 

 

풀이

 

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

댓글