当前位置:网站首页>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;
}
}
边栏推荐
- Shutter uses overlay to realize global pop-up
- The research trend of map based comparative learning (gnn+cl) in the top paper
- Understanding of smt32h7 series DMA and DMAMUX
- Wxss template syntax
- [beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
- Kotlin introductory notes (I) kotlin variables and non variables
- [Yugong series] go teaching course 003-ide installation and basic use in July 2022
- High performance spark_ Transformation performance
- Unity SKFramework框架(二十二)、Runtime Console 运行时调试工具
- OpenGL - Model Loading
猜你喜欢
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
Hosting environment API
[ManageEngine] how to make good use of the report function of OpManager
Creation and reference of applet
LeetCode 496. 下一个更大元素 I
[code practice] [stereo matching series] Classic ad census: (6) multi step parallax optimization
Kotlin introductory notes (VII) data class and singleton class
C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边
Principle and performance analysis of lepton lossless compression
信息與熵,你想知道的都在這裏了
随机推荐
np. allclose
我的一生.
Applet customization component
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
Unity skframework framework (24), avatar controller third person control
Figure neural network + comparative learning, where to go next?
SMT32H7系列DMA和DMAMUX的一点理解
Unity SKFramework框架(二十四)、Avatar Controller 第三人称控制
22-07-04 Xi'an Shanghao housing project experience summary (01)
What is a firewall? Explanation of basic knowledge of firewall
Kotlin introductory notes (V) classes and objects, inheritance, constructors
LeetCode 556. 下一个更大元素 III
Deep understanding of C language pointer
L'information et l'entropie, tout ce que vous voulez savoir est ici.
2310. The number of bits is the sum of integers of K
Blogger article navigation (classified, real-time update, permanent top)
Talking about the difference between unittest and pytest
notepad++
浅谈Label Smoothing技术
3D reconstruction open source code summary [keep updated]