当前位置:网站首页>365天挑战LeetCode1000题——Day 049 非递增顺序的最小子序列 贪心
365天挑战LeetCode1000题——Day 049 非递增顺序的最小子序列 贪心
2022-08-04 14:56:00 【ShowM3TheCode】
1403. 非递增顺序的最小子序列

代码实现(自解)
class Solution {
public:
vector<int> minSubsequence(vector<int>& nums) {
sort(nums.begin(), nums.end(), greater<int>());
int sum = accumulate(nums.begin(), nums.end(), 0);
int ans = 0;
int pnum = 0;
while (ans * 2 <= sum) {
ans += nums[pnum];
pnum++;
}
vector<int> sub;
for (int i = 0; i < pnum; i++) {
sub.push_back(nums[i]);
}
return sub;
}
};
边栏推荐
猜你喜欢
随机推荐
【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常
基本介绍PLSQL
1403. Minimum Subsequence in Non-Increasing Order
C# 判断文件编码
【云原生 | 从零开始学Kubernetes】kubernetes之StatefulSet详解
Oracle database user creation, restart, import and export
I/O stream summary
快解析结合千方百剂
How to automatically renew the token after it expires?
Latex 去掉行号
[Opportunity Enlightenment-60]: "Soldiers, Stupid Ways"-1- Opening: "Death" and "Life" are the way of heaven
C# 谁改了我的代码
宣传海报
数据链路层-------以太网协议
C# 将dll打包到程序中
leetcode: 259. Smaller sum of three numbers
Phasecraft连下两城,助力英国量子技术商业化加速!
leetcode:251. 展开二维向量
Next -18- 添加代码复制按钮
手搓一个“七夕限定”,用3D Engine 5分钟实现烟花绽放效果









