-
34. 예산코딩 테스트/Level 1 2019. 11. 1. 23:33반응형
https://programmers.co.kr/learn/courses/30/lessons/12982
https://comdoc.tistory.com/entry/37-%EC%98%88%EC%82%B0-%EB%AC%B8%EC%A0%9C
파이썬
def solution(d, budget): d.sort() i = 0 for each in d: budget -= each if budget < 0: break i += 1 return i
자바스크립트
function solution(d, budget) { d.sort((a, b) => a - b) for (var i = 0; i < d.length; i++) { budget -= d[i] if (budget < 0) break } return i }
자바
import java.util.Arrays; class Solution { public int solution(int[] d, int budget) { Arrays.sort(d); int i = 0; for (;i < d.length;i++) { budget -= d[i]; if (budget < 0) break; } return i; } }
C#
using System; public class Solution { public int solution(int[] d, int budget) { int answer = 0; Array.Sort(d); foreach(int i in d) { budget -= i; if (budget < 0) break; answer++; } return answer; } }
golang
import "sort" func solution(d []int, budget int) (i int) { sort.Ints(d) for i = 0; i < len(d); i++ { budget -= d[i] if budget < 0 { break } } return i }
반응형