class Solution {
public List<Integer> minSubsequence(int[] nums) {
Arrays.sort(nums);
int sum = 0, cur = 0, index = nums.length - 1;
List<Integer> res = new ArrayList<>();
// 计算数组结果
for (int i : nums) sum += i;
while (cur <= sum){
sum -= nums[index];
cur += nums[index];
res.add(nums[index]);
index--;
}
return res;
}
}
力扣:1403. 非递增顺序的最小子序列
于 2022-08-04 23:36:36 首次发布
本文介绍了一种名为Solution的Java类,它通过排序和动态调整的方法找到一个整数数组中使得和最小的子序列。通过实例代码演示了如何计算并返回这个子序列。适合理解数组问题和排序算法的应用。

372

被折叠的 条评论
为什么被折叠?



