当前位置:网站首页>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;
}
};
边栏推荐
- NPDP|作为产品经理,如何快速提升自身业务素养?
- B. Construct a simple sequence (greedy)
- 宣传海报
- Why does the decimal point appear when I press the space bar in word 2003?
- Oracle database user creation, restart, import and export
- License server system does not support this version of this feature
- leetcode: 253. How many meeting rooms are required at least
- 微软表示将向内部网络安全专家共享数据 为企业提供更安全保护
- 谷歌插件.crx文件下载后被自动删除的解决方法
- leetcode:215无序数组中找第k大的元素
猜你喜欢

Bluetooth Technology|In the first half of the year, 1.3 million charging piles were added nationwide, and Bluetooth charging piles will become the mainstream of the market

本周讨论用户体验:Daedalus 的 Nemo 加入 Ambire,探索加密海洋

【 HMS core 】 【 Media 】 online video editing service 】 【 material can't show, or network anomalies have been Loading state

IP第十六天笔记

数据库恢复

利用决策树找出最优特征组合

leetcode:259. 较小的三数之和

编译型与解释型编程语言的区别

实际工作中的高级技术(训练加速、推理加速、深度学习自适应、对抗神经网络)

Leetcode: 215 disorderly to find the first big k element in the array
随机推荐
编译型与解释型编程语言的区别
《分布式云最佳实践》分论坛,8月11日深圳见
用了TCP协议,就一定不会丢包吗?
MVCC实现过程
关于pnpm包管理器的版本问题
华为云 & 达达,帮有情人“一键送达”
xampp安装包含的组件有(php,perl,apche,mysql)
聊聊与苹果审核员的爱恨情仇
C# BBcode 转 Markdown
vim common operation commands
16、学习MySQL 正则表达式
ping的原理
How to fall in love with a programmer
用于X射线聚焦的复合折射透镜
输入输出流总结
基本介绍PLSQL
快解析结合友加畅捷U+
1403. Minimum Subsequence in Non-Increasing Order
I love Tanabata hahaha
C# SolidWorks二次开发---工程图简单版标注孔信息