当前位置:网站首页>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;
}
};
边栏推荐
- Almost all known protein structures in the world are open sourced by DeepMind
- 杭电校赛(ACM组队安排)
- Database recovery
- 第十六章 源代码文件 REST API 教程(一)
- IP第十八天笔记
- C# 将dll打包到程序中
- F. Jinyu and its outer matrix (construction)
- Google plug-in. Download contents file is automatically deleted after solution
- License server system does not support this version of this feature
- leetcode: 255 Verify preorder traversal sequence binary search tree
猜你喜欢
大众点评搜索相关性技术探索与实践
leetcode:251. 展开二维向量
[Beiya data recovery] IBM System Storage storage lvm information lost data recovery solution
期货开户之前要谈好最低手续费和交返
【剑指offer33】二叉搜索树的后序遍历序列
16. Learn MySQL Regular Expressions
Technology sharing | Description of the electronic fence function in the integrated dispatching system
CloudCompare&PCL 点云按网格划分(点云分幅)
leetcode:212. 单词搜索 II
IP第十六天笔记
随机推荐
AOSP built-in APP franchise rights white list
1403. 非递增顺序的最小子序列
Oracle database user creation, restart, import and export
uni-app 从零开始-生命周期(二)
Android Sqlite3基本命令
Android Sqlite3 basic commands
Hangzhou Electric School Competition (Counter Attack Index)
xampp安装包含的组件有(php,perl,apche,mysql)
How to write SQL statements: the usage of Update, Case, and Select together
leetcode:259. 较小的三数之和
Makefile syntax and usage notes
IP第十八天笔记
Cisco - Small Network Topology (DNS, DHCP, Web Server, Wireless Router)
快解析结合千方百剂
C# 判断文件编码
杭电校赛(ACM组队安排)
This week to discuss the user experience: Daedalus Nemo to join Ambire, explore the encryption of the ocean
FRED Application: Capillary Electrophoresis System
Workaround without Project Facets
leetcode:253. 至少需要多少间会议室