当前位置:网站首页>2022.7.3-----leetcode. five hundred and fifty-six
2022.7.3-----leetcode. five hundred and fifty-six
2022-07-04 05:55:00 【Lu 727】
public int nextGreaterElement(int n) {
if(n<10) return -1;
int num=n;// Save original number
// Split the numbers in reverse order
int idx=0;
int[] arr=new int[String.valueOf(n).length()];
while(n>0){
arr[idx++]=n%10;
n/=10;
}
// Start from the low position at [0,i-1] The range search is greater than arr[i] Replace with the smallest number of arr[i], Then sort the following from large to small
for(int i=1;i<arr.length;i++){
int k=0;// Decimal index
int min=10;// Greater than arr[i] The minimum value of
for(int j=0;j<i;j++){
if(arr[j]>arr[i]&&arr[j]<min){
min=arr[j];
k=j;
}
}
if(min==10) continue;// Can't find , It means that this bit must be followed by order
// And arr[i] In exchange for
int tmp1=arr[k];
arr[k]=arr[i];
arr[i]=tmp1;
// Sort the following numbers
for(int l=i-1;l>0;l--){
boolean ex=false;
for(int j=0;j<l;j++){
if(arr[j]<arr[l]){
int tmp2=arr[j];
arr[j]=arr[l];
arr[l]=tmp2;
ex=true;
}
}
if(!ex) break;
}
break;// Go back when you find it
}
// synthesis
long ans=0;
for(int i=arr.length-1;i>=0;i--){
ans=ans*10+arr[i];
}
// Judge whether it is legal
if(ans==num||ans>Integer.MAX_VALUE) return -1;
return (int)ans;
}边栏推荐
- BeanFactoryPostProcessor 与 BeanPostProcessor 相关子类概述
- ansys命令
- Sword finger offer II 038 Daily temperature
- 检漏继电器JY82-2P
- How to configure static IP for Kali virtual machine
- Review | categories and mechanisms of action of covid-19 neutralizing antibodies and small molecule drugs
- Use of hutool Pinyin tool
- Recommended system 1 --- framework
- gslb(global server load balance)技术的一点理解
- js arguments参数使用和详解
猜你喜欢

gslb(global server load balance)技术的一点理解

BUU-Crypto-Cipher

Uninstall Google drive hard drive - you must exit the program to uninstall
![[excel] PivotChart](/img/45/be87e4428a1d8ef66ef34a63d12fd4.png)
[excel] PivotChart

复合非线性反馈控制(二)

体验碎周报第 102 期(2022.7.4)

Accidentally deleted the data file of Clickhouse, can it be restored?

QT 获取随机颜色值设置label背景色 代码

JS how to convert seconds into hours, minutes and seconds display

Upper computer software development - log information is stored in the database based on log4net
随机推荐
Detectron:训练自己的数据集——将自己的数据格式转换成COCO格式
HMS v1.0 appointment. PHP editid parameter SQL injection vulnerability (cve-2022-25491)
Tutle clock improved version
Arc135 a (time complexity analysis)
Layoutmanager layout manager: flowlayout, borderlayout, GridLayout, gridbaglayout, CardLayout, BoxLayout
Understanding of cross domain and how to solve cross domain problems
AWT介绍
Introduction To AMBA 简单理解
[excel] PivotChart
实用的小工具指令
Uninstall Google drive hard drive - you must exit the program to uninstall
体验碎周报第 102 期(2022.7.4)
【微服务】Nacos集群搭建以及加载文件配置
Halcon图片标定,使得后续图片处理过后变成与模板图片一样
Review | categories and mechanisms of action of covid-19 neutralizing antibodies and small molecule drugs
Win10 clear quick access - leave no trace
Design and implementation of tcp/ip series overview
BUU-Crypto-[GXYCTF2019]CheckIn
Leetcode 184 Employees with the highest wages in the Department (July 3, 2022)
C语言练习题(递归)