当前位置:网站首页>31. Next arrangement
31. Next arrangement
2022-04-23 12:51:00 【anieoo】
Original link :31. Next spread
solution: Brain teaser // After reading the solution to the problem, I will come to the idea orz
class Solution {
public:
void nextPermutation(vector<int>& nums) {
int k = nums.size() - 1;
while(k && nums[k - 1] >= nums[k]) k--; //k Greater than 0 And satisfy that the next number is greater than or equal to this number ,k--
if(k == 0){ //k == 0 Description the array is arranged in full descending order
sort(nums.begin(),nums.end());
return;
}
else{
int t = k;
while(t < nums.size() && nums[t] > nums[k - 1]) t++;
swap(nums[t - 1],nums[k - 1]);
reverse(nums.begin() + k,nums.end());
}
}
};
版权声明
本文为[anieoo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231248410328.html
边栏推荐
猜你喜欢

31. 下一个排列

Remote sensing image classification and recognition system based on convolutional neural network

梳理網絡IP代理的幾大用途

SSM框架系列——注解开发day2-2

Idea的src子文件下无法创建servlet

Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
![[vulnhub range] - DC2](/img/b7/c34f69a231dad653b8a912f1f36bef.png)
[vulnhub range] - DC2

【unity笔记】L4Unity中的基础光照

软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。

【每日一题】棋盘问题
随机推荐
Metalama简介4.使用Fabric操作项目或命名空间
Homomorphic encryption technology learning
BUUCTF WEB [BUUCTF 2018]Online Tool
Stacks and queues a
免费试用一个月的服务器,并附上教程
力扣刷题之完全二叉树的节点个数
CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
解决disagrees about version of symbol device_create
有趣的IDEA插件推荐,给你的开发工作增添色彩
box-sizing
8 websites that should be known for product development to enhance work experience
98. Error s.e.errormvcautoconfiguration $staticview reported by freemaker framework: cannot render error page for request
S2-062 remote command execution vulnerability recurrence (cve-2021-31805)
进程虚拟地址空间区域划分
I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings
4.DRF 权限&访问频率&过滤&排序
Remote sensing image classification and recognition system based on convolutional neural network
Sort out several uses of network IP agent
leetcode:437. 路径总和 III【dfs 选还是不选?】
NPDP | how can product managers not be excluded by programmers?