Summer/Winter Coding(~2018)
https://programmers.co.kr/learn/courses/30/lessons/12982
#오름차순정렬#배열의합#sort#reduce
def solution(d, budget):
d = sorted(d)
if sum(d) <= budget :
return len(d)
else :
sum_d = 0
i = 0
while sum_d <= budget :
sum_d += d[i]
i += 1
return i-1
function solution(d, budget) {
let lengD = d.length;
let sortD = d.sort((a,b) => a-b);
let sumD = d.reduce((a,b) => a+b);
if(sumD <= budget){
return lengD;
} else {
let sum = 0;
let i = 0;
while(sum <= budget){
sum += sortD[i];
i++;
}
return i-1;
}
}