当前位置:网站首页>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
边栏推荐
- Keyword interpretation and some APIs in RT thread
- SSM framework series - JUnit unit test optimization day2-3
- Kubernets Getting started tutoriel
- 对话PostgreSQL作者Bruce:“转行”是为了更好地前行
- 如何防止网站被黑客入侵篡改
- Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
- C, calculation code of parameter points of two-dimensional Bezier curve
- Kubernetes 入門教程
- QT draw text
- Message queuing overview
猜你喜欢

What are the forms of attack and tampering on the home page of the website

QT draw text

QT interprocess communication

Kubernets Getting started tutoriel

No idle servers? Import OVF image to quickly experience smartx super fusion community version

Image attribute of input: type attribute of fashion cloud learning -h5

力扣刷题之完全二叉树的节点个数

Trier les principales utilisations de l'Agent IP réseau

Wonderful review | the sixth issue of "source" - open source economy and industrial investment

Number of nodes of complete binary tree
随机推荐
BUUCTF WEB [BUUCTF 2018]Online Tool
QT draw image
SSM框架系列——Junit单元测试优化day2-3
基于卷积神经网络的遥感影像分类识别系统
CGC: contractual graph clustering for community detection and tracking
Wonderful review | the sixth issue of "source" - open source economy and industrial investment
STM32工程移植:不同型号芯片工程之间的移植:ZE到C8
A graphic designer's fantasy world | ones characters
梳理网络IP代理的几大用途
RT-thread中关键词解释及部分API
[unity note] basic lighting in l4unity
BUUCTF WEB [BUUCTF 2018]Online Tool
Keyword interpretation and some APIs in RT thread
Stm32cubeprogrammer basic instructions
[csnote] ER diagram
在线计算过往日期天数,计算活了多少天
I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings
力扣刷题之完全二叉树的节点个数
A graphic designer's fantasy world | ones characters
【unity笔记】L4Unity中的基础光照