当前位置:网站首页>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;
}
}
边栏推荐
- Introduction Guide to stereo vision (1): coordinate system and camera parameters
- c语言指针深入理解
- Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
- What is a firewall? Explanation of basic knowledge of firewall
- 混淆矩阵(Confusion Matrix)
- Kotlin introductory notes (VIII) collection and traversal
- scipy. misc. imread()
- 基于STM32单片机的测温仪(带人脸检测)
- Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
- Svgo v3.9.0+
猜你喜欢

Newton iterative method (solving nonlinear equations)
![Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]](/img/d8/39020b1ce174299f60b6f278ae0b91.jpg)
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]

Nodemon installation and use

Using request headers to develop multi terminal applications

Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning

Progressive JPEG pictures and related

Attention is all you need

Applet (global data sharing)

Nodejs modularization

C language - input array two-dimensional array a from the keyboard, and put 3 in a × 5. The elements in the third column of the matrix are moved to the left to the 0 column, and the element rows in ea
随机推荐
Kotlin introductory notes (III) kotlin program logic control (if, when)
2011-11-21 training record personal training (III)
Applet (subcontracting)
Talking about label smoothing technology
C language - input array two-dimensional array a from the keyboard, and put 3 in a × 5. The elements in the third column of the matrix are moved to the left to the 0 column, and the element rows in ea
NIPS2021 | 超越GraphCL,GNN+对比学习的节点分类新SOTA
Analysis of eventbus source code
Lepton 无损压缩原理及性能分析
Svg optimization by svgo
Wechat applet obtains household area information
高性能Spark_transformation性能
Information and entropy, all you want to know is here
Generate confrontation network
22-07-04 西安 尚好房-项目经验总结(01)
2311. 小于等于 K 的最长二进制子序列
Rebuild my 3D world [open source] [serialization-2]
一篇文章带你走进cookie,session,Token的世界
It's too difficult to use. Long articles plus pictures and texts will only be written in short articles in the future
Greendao reported an error in qigsaw, could not init daoconfig
云计算技术热点