当前位置:网站首页>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
边栏推荐
- 【vulnhub靶场】-dc2
- Image attribute of input: type attribute of fashion cloud learning -h5
- Jiachen chapter Genesis "inner universe" joint Edition
- Introduction to kubernetes
- leetcode:437. 路径总和 III【dfs 选还是不选?】
- 98. Error s.e.errormvcautoconfiguration $staticview reported by freemaker framework: cannot render error page for request
- 力扣刷题之完全二叉树的节点个数
- leetcode-791. Custom string sorting
- 解决disagrees about version of symbol device_create
- Markdown grammar learning
猜你喜欢
如何实现点击一下物体播放一次动画
教你快速开发一个 狼人杀微信小程序(附源码)
Introduction to kubernetes
If you were a golang interviewer, what questions would you ask?
NPDP|产品经理如何做到不会被程序员排斥?
Resolve disagrees about version of symbol device_ create
解锁OpenHarmony技术日!年度盛会,即将揭幕!
精度、速度完美平衡,最新图像分割SOTA模型重磅发布!!!
Image attribute of input: type attribute of fashion cloud learning -h5
梳理網絡IP代理的幾大用途
随机推荐
Object.keys后key值数组乱序的问题
XinChaCha Trust SSL Organization Validated
Uni app native app cloud packaging integrated Aurora push (jg-jpush) detailed tutorial
box-sizing
Aviation core technology sharing | overview of safety characteristics of acm32 MCU
只是不断地建构平台,不断地收拢流量,并不能够做好产业互联网
Realize several "Postures" in which a box is horizontally and vertically centered in the parent box
Wonderful review | the sixth issue of "source" - open source economy and industrial investment
软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
Recommended website for drawing result map
Plato farm - a game of farm metauniverse with Plato as the goal
Bert base Chinese Download (SMART)
leetcode:437. 路径总和 III【dfs 选还是不选?】
Sort out several uses of network IP agent
What are the forms of attack and tampering on the home page of the website
mysql中 innoDB执行过程分析
Luogu p3236 [hnoi2014] picture frame solution
STM32控制步进电机(ULN2003+28byj)
Markdown语法学习
Kubernets Getting started tutoriel