1403. 非递增顺序的最小子序列
代码:
class Solution {public List<Integer> minSubsequence(int[] nums) {List<Integer> list = new ArrayList<>();int max = Integer.MIN_VALUE, index = 0;Arrays.sort(nums);for (int i = nums.length - 1; i >= 0; i--){int sum1 = 0, sum2 = 0;for (int j = 0; j < i; j++) sum1 += nums[j];for (int j = nums.length-1; j >= i; j--) sum2 += nums[j];if (sum2 >= sum1 && max < sum2) {max = sum2;index = i;}}for (int i = nums.length - 1; i >= index; i--) list.add(nums[i]);return list;}
}