当前位置:网站首页>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;
}
};
边栏推荐
- How to write SQL statements: the usage of Update, Case, and Select together
- CF1527D MEX Tree (mex & tree & inclusive)
- Next -20- 使用自定义样式 (custom style)
- Notes for xpath getting node with namespace
- 基于数据库实现分布式锁
- leetcode: 255 Verify preorder traversal sequence binary search tree
- leetcode:259. 较小的三数之和
- Basic Introduction for PLSQL
- using关键字学习
- Makefile 语法及使用笔记
猜你喜欢
ping的原理
什么,你告诉我?作用域也分种类?
世间几乎所有已知蛋白质结构,都被DeepMind开源了
1403. Minimum Subsequence in Non-Increasing Order
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
Compound Refractive Lenses for X-ray Focusing
程序猿七夕礼物-如何30分钟给女朋友快速搭建专属语聊房
token 过期后,如何自动续期?
IP第十六天笔记
微软表示将向内部网络安全专家共享数据 为企业提供更安全保护
随机推荐
[深入研究4G/5G/6G专题-50]: URLLC-16-《3GPP URLLC相关协议、规范、技术原理深度解读》-10-高可靠性技术-1-低编码率编码调制方案MCS与高可靠性DRB
[The Art of Hardware Architecture] Study Notes (1) The World of Metastability
Basic Introduction for PLSQL
IP第十六天笔记
CF1527D MEX Tree(mex&树&容斥)
C# 谁改了我的代码
如何和程序员谈恋爱
Compound Refractive Lenses for X-ray Focusing
Oracle 数据库用户创建、重启、导入导出
16、学习MySQL 正则表达式
Set partition minimum difference problem (01 knapsack)
C# TextBlock 上标
[in-depth study of 4 g / 5 g / 6 g project - 50] : URLLC - 16 - the 3 GPP URLLC agreement, specification, technical principle of depth interpretation - 10 - high reliability technology - 1 - low codin
IP第十五天笔记
Leetcode: 215 disorderly to find the first big k element in the array
C语言写简单三子棋
leetcode:254. 因子的组合
leetcode:250. 统计同值子树
[机缘参悟-60]:《兵者,诡道也》-1-开篇:“死“与“生“都是天道
7 天能找到 Go 工作吗?学学 Go 数组和指针试试