로딩
요청 처리 중입니다...

JAVA_LeetCode 1710_Maximum Units on a Truck

 JAVA_LeetCode 1710_Maximum Units on a Truck

JAVA_LeetCode 1710_Maximum Units on a Truck 풀이 class Solution { public int maximumUnits(int[][] boxTypes, int truckSize) { // 상자를 내림차순으로 정렬 int cnt = 0; Arrays.sort(boxTypes, (a, b)-> b[1] - a[1]); // 상자 개수 초과 x, 트럭사이즈 확인(내림차순이므로 개수파악 확인 가능) for(int i = 0; i < boxTypes.length && truckSize > 0; i++){ if(boxTypes[i][0] < truckSize){ cnt+= boxTypes[i][0] * boxTypes[i][1]; truckSize -= boxTypes[i][0]; }else{ cnt += truckSize * boxTypes[i][1]; break; } } return cnt; } } * 출처 https://leetcode.com/prob...

# JAVA # JAVA_LeetCode1710 # JAVA_LeetCode1710_MaximumUnitsonaTruck # JAVA_MaximumUnitsonaTruck # LeetCode1710_MaximumUnitsonaTruck