当前位置:网站首页>【2022暑期】【LeetCode】31. 下一个排列
【2022暑期】【LeetCode】31. 下一个排列
2022-06-22 11:20:00 【之井】
学习思路,注意是从后面开始查
class Solution {
public void nextPermutation(int[] nums) {
int len = nums.length;
int i = 0;
for(i=len-1; i>0; i--){
if(nums[i]<=nums[i-1]) continue;
else{
int l = 0;
int min = Integer.MAX_VALUE;
for(int k=i; k<len; k++){
if(nums[k]>nums[i-1]&&nums[k]<min){
l = k;
min = nums[k];
}
}
swap(nums,l,i-1);
Arrays.sort(nums,i,len);
break;
}
}
if(i==0) Arrays.sort(nums);
}
public void swap(int[] nums,int i,int j){
int a = nums[i];
nums[i] = nums[j];
nums[j] = a;
}
}
虽然是照着题解,但是不摆烂!
边栏推荐
- Idr Display function obtains the summary statistical information of Poisson regression Poisson model (initial event density ratio IDR value, adjusted event density ratio IDR value and its confidence i
- 奋斗吧,程序员——第四十六章 此情可待成追忆,只是当时已惘然
- Noi use cases
- R language performs two sample t-test on the specified covariates based on the with function, and the t.test function performs Welch two sample t-test analysis and two independent sample t-test on the
- xlrd. biffh. XLRDError: Excel xlsx file; Not supported solution
- Haas506 2.0 development tutorial - Advanced Component Library -modem Info (only supports versions above 2.2)
- R语言使用自定义函数编写深度学习Parametric ReLU激活函数、并可视化Parametric ReLU激活函数
- 配置GPU版本的pytorch和torchvision,初学GPU版本torch踩坑
- NOI使用案例
- The father of the college entrance examination student told himself at night that what he cared about most was not the child's performance, and the turning point was not false at all
猜你喜欢
随机推荐
IO之ByteStream案例
从原型链到继承,图解来龙去脉,推荐收藏
奋斗吧,程序员——第三十七章.雄关漫道真如铁,而今迈步从头越
SAVE: 软件分析验证和测试平台
Cookies and sessions for answers to common interview questions
R语言epiDisplay包的idr.display函数获取泊松回归poisson模型的汇总统计信息(初始事件密度比IDR值、调整事件密度比IDR值及其置信区间、Wald检验的p值和似然比检验的p值)
2022年度敏捷教练行业现状报告(2022 State of Agile Coaching Report)
如果你是个半路出家的程序员,请一字一句的看完
In a word, several common methods of uploading Trojan horse
牛客挑战赛54E题解
CISP textbook update: introduction to the new knowledge system of eight knowledge domains in 2019
Two ways of traversing binary tree: preorder, inorder and postorder
Rtklib postpos carding (taking single point positioning as an example)
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、使用lm函数对匹配后的样本构建线性回归模型、summary函数查看模型的汇总统计信息
General graph maximum matching (with flower tree) template
How to improve customer conversion rate on the official website
IO之ByteArrayStream案例
Bytearraystream case of IO
牛客挑战赛57C题解
Development technology of NFT trading platform digital collection system









