当前位置:网站首页>LeetCode 556. Next bigger element III
LeetCode 556. Next bigger element III
2022-07-05 09:26:00 【Sasakihaise_】
【 analysis 】 This and 31. Next spread It's the same .
But we need to pay attention to the super int The extent of the situation
class Solution {
public int nextGreaterElement(int n) {
char[] s = String.valueOf(n).toCharArray();
int m = s.length;
if (m == 1) {
return -1;
}
int i, j;
for (i = m - 2; i >= 0; i--) {
if (s[i] < s[i + 1]) {
break;
}
}
if (i == -1) {
return -1;
}
for (j = m - 1; j > i; j--) {
if (s[j] > s[i]) {
break;
}
}
char t = s[i];
s[i] = s[j];
s[j] = t;
Arrays.sort(s, i + 1, m);
long ans = Long.parseLong(String.valueOf(s));
if (ans > ((long)1 << 31) - 1) return -1;
return (int)ans;
}
}
边栏推荐
- Global configuration tabbar
- Luo Gu p3177 tree coloring [deeply understand the cycle sequence of knapsack on tree]
- Kotlin introductory notes (V) classes and objects, inheritance, constructors
- Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
- [code practice] [stereo matching series] Classic ad census: (5) scan line optimization
- OpenGL - Coordinate Systems
- 一次 Keepalived 高可用的事故,让我重学了一遍它
- Alibaba's ten-year test brings you into the world of APP testing
- Uni app implements global variables
- 生成对抗网络
猜你喜欢

Blogger article navigation (classified, real-time update, permanent top)

Kotlin introductory notes (II) a brief introduction to kotlin functions

22-07-04 西安 尚好房-项目经验总结(01)

一次 Keepalived 高可用的事故,让我重学了一遍它
![Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]](/img/7d/e7370e757c18b3dbb47e633703c346.jpg)
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]

Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning
![[reading notes] Figure comparative learning gnn+cl](/img/44/2e13d63ef654663852cbccb342b838.png)
[reading notes] Figure comparative learning gnn+cl

Editor use of VI and VIM

High performance spark_ Transformation performance

SMT32H7系列DMA和DMAMUX的一点理解
随机推荐
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
Hosting environment API
Kotlin introductory notes (III) kotlin program logic control (if, when)
Explain NN in pytorch in simple terms CrossEntropyLoss
信息与熵,你想知道的都在这里了
Introduction Guide to stereo vision (7): stereo matching
Unity skframework framework (XXII), runtime console runtime debugging tool
OpenGL - Lighting
高性能Spark_transformation性能
Huber Loss
Deep understanding of C language pointer
22-07-04 Xi'an Shanghao housing project experience summary (01)
Uni app implements global variables
Can't find the activitymainbinding class? The pit I stepped on when I just learned databinding
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
Global configuration tabbar
Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
阿里十年测试带你走进APP测试的世界
C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边