当前位置:网站首页>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;
}
}
边栏推荐
- Codeworks round 681 (Div. 2) supplement
- Introduction Guide to stereo vision (7): stereo matching
- Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
- STM32简易多级菜单(数组查表法)
- Thermometer based on STM32 single chip microcomputer (with face detection)
- An article takes you into the world of cookies, sessions, and tokens
- Principle and performance analysis of lepton lossless compression
- Applet network data request
- Editor use of VI and VIM
- [code practice] [stereo matching series] Classic ad census: (5) scan line optimization
猜你喜欢

Introduction Guide to stereo vision (1): coordinate system and camera parameters

OpenGL - Model Loading

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

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

Principle and performance analysis of lepton lossless compression

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

Huber Loss

Applet data attribute method

Deep understanding of C language pointer

High performance spark_ Transformation performance
随机推荐
Unity skframework framework (XXII), runtime console runtime debugging tool
[code practice] [stereo matching series] Classic ad census: (6) multi step parallax optimization
nodejs_ 01_ fs. readFile
Huber Loss
An article takes you into the world of cookies, sessions, and tokens
Kotlin introductory notes (V) classes and objects, inheritance, constructors
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
[ManageEngine] how to make good use of the report function of OpManager
Understanding rotation matrix R from the perspective of base transformation
2310. 个位数字为 K 的整数之和
Talking about label smoothing technology
Wechat applet obtains household area information
Generate confrontation network
浅谈Label Smoothing技术
Jenkins pipeline method (function) definition and call
Nodejs modularization
np.allclose
Alibaba's ten-year test brings you into the world of APP testing
Attention is all you need
信息與熵,你想知道的都在這裏了