当前位置:网站首页>31. 下一个排列
31. 下一个排列
2022-04-23 12:48:00 【anieoo】
原题链接:31. 下一个排列
solution:脑筋急转弯的题 //看了题解才会到的思路orz
class Solution {
public:
void nextPermutation(vector<int>& nums) {
int k = nums.size() - 1;
while(k && nums[k - 1] >= nums[k]) k--; //k大于0且满足下一个数大于等于这个数,k--
if(k == 0){ //k == 0说明数组完全降序排列
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://blog.csdn.net/qq_42174306/article/details/124362310
边栏推荐
- Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
- BUUCTF WEB [BJDCTF2020]The mystery of ip
- Unable to create servlet under SRC subfile of idea
- Kubernetes 入门教程
- Introduction to kubernetes
- 风尚云网学习-input属性总结
- Object. The disorder of key value array after keys
- Analysis of InnoDB execution process in MySQL
- 【蓝桥杯】4月17日省赛刷题训练(前3道题)
- Stm32cubeprogrammer basic instructions
猜你喜欢
QT interprocess communication
有趣的IDEA插件推荐,给你的开发工作增添色彩
梳理網絡IP代理的幾大用途
Qt双缓冲绘图
A graphic designer's fantasy world | ones characters
[csnote] ER diagram
Everything can be expected in the future | one 2022 campus recruitment officially opened
【vulnhub靶场】-dc2
大家帮我看一下这是啥情况,MySQL5.5的。谢了
Redis deployment of cloud native kubesphere
随机推荐
C#,二维贝塞尔拟合曲线(Bézier Curve)参数点的计算代码
Remote sensing image classification and recognition system based on convolutional neural network
RT-thread中关键词解释及部分API
Try the server for one month for free, and attach the tutorial
Stacks and queues a
8 websites that should be known for product development to enhance work experience
BUUCTF WEB [BUUCTF 2018]Online Tool
leetcode:437. Path sum III [DFS selected or not selected?]
【微信小程序】z-index失效
QT draw text
QT redraw events and cuts
Metalama简介4.使用Fabric操作项目或命名空间
有趣的IDEA插件推荐,给你的开发工作增添色彩
洛谷P3236 [HNOI2014]画框 题解
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
Analysis of InnoDB execution process in MySQL
21 days learning mongodb notes
C, calculation code of parameter points of two-dimensional Bezier curve
只是不断地建构平台,不断地收拢流量,并不能够做好产业互联网
Uni app native app cloud packaging integrated Aurora push (jg-jpush) detailed tutorial