当前位置:网站首页>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;
}
};
边栏推荐
- Nvidia's gaming graphics card revenue plummets / Google data center explosion injures 3 people / iPhone battery percentage returns... More news today is here...
- 【API Management】What is API Management and why is it important?
- Development environment variable record under win
- Flink快速上手 完整使用 (第二章)
- 属性动画QPropertyAnimation
- 并发的基本概念,操作,容器
- Which is the strongest workflow engine for "Technology Selection"?Chief Architecture Helps You Pick
- 「数据架构」:主数据管理(MDM)对我的行业有什么帮助?
- WebView2 通过 PuppeteerSharp 实现爬取 王者 壁纸 (案例版)
- 英伟达游戏显卡营收暴跌/ 谷歌数据中心爆炸致3人受伤/ iPhone电量百分比回归…今日更多新鲜事在此...
猜你喜欢

傅立叶级数与傅里叶变换

2022 首期线下 Workshop!面向应用开发者们的数据应用体验日来了 | TiDB Workshop Day

Defending risks with technology and escorting cloud native | Tongchuang Yongyi X Boyun held a joint product launch conference

关于编程本质那些事

哈希表,哈希桶的实现

解决ASP.NET Core在Task中使用IServiceProvider的问题

WebView2 通过 PuppeteerSharp 实现爬取 王者 壁纸 (案例版)

2022-08-09 第六小组 瞒春 学习笔记

DeepFake换脸诈骗怎么破?让他侧个身
![[Data Architecture] Distributed Data Grid as a Solution for Centralized Data Monolith](/img/99/b22268e3e47db9e9caad58722e8709.png)
[Data Architecture] Distributed Data Grid as a Solution for Centralized Data Monolith
随机推荐
属性动画QPropertyAnimation
支付 x 聚合 x 分账 - 回流平台“二清”风险规避之路
ES复杂操作搜索
The first offline workshop in 2022!Data application experience day for application developers is coming | TiDB Workshop Day
重学冒泡排序
2022 首期线下 Workshop!面向应用开发者们的数据应用体验日来了 | TiDB Workshop Day
04 【计算属性 侦听器】
解决ASP.NET Core在Task中使用IServiceProvider的问题
「应用架构」TOGAF建模:应用程序迁移图
ESP8266-Arduino编程实例-MQ-9 一氧化碳可燃气体传感器驱动
Tencent releases the second-generation version of the quadruped robot Max, which completes jumps and somersaults on the plum blossom pile
LiveNVR操作日志页面快速筛选上级国标平台的调用记录直播观看录像回看等操作
乐观锁与悲观锁
英伟达游戏显卡营收暴跌/ 谷歌数据中心爆炸致3人受伤/ iPhone电量百分比回归…今日更多新鲜事在此...
The web project accesses static resources inside the reference jar
"Guangzhou highway engineering measures for the supervision and administration of production safety, and revised from six aspects
CAD转WPF: 关于CAD图纸文件转换为WPF矢量代码文件(xaml文件)的技巧
「业务架构」TOGAF建模:组织分解图(组织映射)
Singleton pattern base class
90.(cesium之家)cesium高度监听事件