1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class Solution { public List<Integer> minSubsequence(int[] nums) { Arrays.sort(nums);
int total = 0; for (int i = nums.length - 1; i >= 0; i--) { total += nums[i]; }
int curTotal = 0; List<Integer> result = new ArrayList<>(); for (int i = nums.length - 1; i >= 0; i--) { result.add(nums[i]); curTotal += nums[i]; if (curTotal > total - curTotal) { break; } } return result; } }
|