当前位置:网站首页>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;
}
};
边栏推荐
- QT笔记——QUuid了解
- 基本介绍PLSQL
- Compound Refractive Lenses for X-ray Focusing
- G. Mountaineering Squad (violence & dfs)
- leetcode:255 验证前序遍历序列二叉搜索树
- This week to discuss the user experience: Daedalus Nemo to join Ambire, explore the encryption of the ocean
- 本周讨论用户体验:Daedalus 的 Nemo 加入 Ambire,探索加密海洋
- using关键字学习
- How to fall in love with a programmer
- 【Web技术】1401- 图解 Canvas 入门
猜你喜欢

Qt的QItemDelegate使用

Go 语言快速入门指南: 变量和常量

leetcode:212. 单词搜索 II

This week to discuss the user experience: Daedalus Nemo to join Ambire, explore the encryption of the ocean

IP第十八天笔记

Technology sharing | Description of the electronic fence function in the integrated dispatching system

leetcode: 255 Verify preorder traversal sequence binary search tree

快解析结合千方百剂

leetcode: 241. Designing precedence for arithmetic expressions

实际工作中的高级技术(训练加速、推理加速、深度学习自适应、对抗神经网络)
随机推荐
谷歌插件.crx文件下载后被自动删除的解决方法
AOSP built-in APP franchise rights white list
token 过期后,如何自动续期?
Cisco-小型网络拓扑(DNS、DHCP、网站服务器、无线路由器)
Android Sqlite3基本命令
leetcode: 254. Combinations of factors
leetcode:215无序数组中找第k大的元素
[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
Oracle 数据库用户创建、重启、导入导出
F. Jinyu and its outer matrix (construction)
技术分享| 融合调度系统中的电子围栏功能说明
ASA归因:如何评估关键词的投放价值
B. Construct a simple sequence (greedy)
AOSP内置APP特许权限白名单
I love Tanabata hahaha
CF1527D MEX Tree(mex&树&容斥)
大众点评搜索相关性技术探索与实践
G.登山小分队(暴力&dfs)
【Web技术】1401- 图解 Canvas 入门
关于pnpm包管理器的版本问题