当前位置:网站首页>LeetCode Algorithm 1403. 非递增顺序的最小子序列
LeetCode Algorithm 1403. 非递增顺序的最小子序列
2022-08-10 09:55:00 【Alex_996】
题目链接:1403. 非递增顺序的最小子序列
Ideas
算法:迭代
数据结构:无
思路:先把nums
排个序,然后从后往前取,如果当前取得数之和大于剩下的数,则break。
Code
C++
class Solution {
public:
vector<int> minSubsequence(vector<int>& nums) {
vector<int> ans;
int total = accumulate(nums.begin(), nums.end(), 0), curSum = 0;
sort(nums.begin(), nums.end());
for (int i = nums.size() - 1; i > -1; i--) {
curSum += nums[i];
ans.emplace_back(nums[i]);
if (total - curSum < curSum) {
break;
}
}
return ans;
}
};
边栏推荐
- The first offline workshop in 2022!Data application experience day for application developers is coming | TiDB Workshop Day
- 初识Flink 完整使用 (第一章)
- 中国驻越南使馆提醒在越北部、中部地区中国公民做好台风“木兰”安全防范
- Plot temperature curves; QChart,
- 【系统设计】S3 对象存储
- 因子分析(SPSS)
- UE4 Sequence添加基础动画效果 (05-蓝图触发Sequence)
- 「业务架构」TAGAF建模:业务服务/信息图
- 单例模式基类
- 90.(cesium之家)cesium高度监听事件
猜你喜欢
随机推荐
shell------常用小工具,sort,uniq,tr,cut
go web之cookie
08 【Props 组件事件】
【软考 系统架构设计师】系统可靠性分析与设计① 系统可靠性分析
"Guangzhou highway engineering measures for the supervision and administration of production safety, and revised from six aspects
「数据架构」数据模型,数据字典,数据库模式 和ERD的比较
web项目访问引用jar内部的静态资源
ES复杂操作搜索
shell iterates over folders and outputs
Guo Jingjing's personal chess teaching, the good guy is a robot
VBA: 采用Combox控件实现二级下拉菜单功能
LCD模块如何建立联系分析
ESP8266-Arduino编程实例-MQ-9 一氧化碳可燃气体传感器驱动
win下的开发环境变量记录
The web project accesses static resources inside the reference jar
属性动画QPropertyAnimation
"Data Architecture": How can master data management (MDM) help my industry?
郭晶晶家的象棋私教,好家伙是个机器人
【Prometheus】Node Exporter常用查询PromQL 语句大总结
How to understand the difference between BIO, NIO, and AIO