当前位置:网站首页>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;
}
}
边栏推荐
- Applet network data request
- 一次 Keepalived 高可用的事故,让我重学了一遍它
- 信息與熵,你想知道的都在這裏了
- Unity skframework framework (XXIII), minimap small map tool
- Hosting environment API
- Applet global style configuration window
- [ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)
- 项目实战 | Excel导出功能
- Using request headers to develop multi terminal applications
- Alibaba cloud sends SMS verification code
猜你喜欢
信息与熵,你想知道的都在这里了
OpenGL - Model Loading
Node collaboration and publishing
OpenGL - Model Loading
混淆矩阵(Confusion Matrix)
What is a firewall? Explanation of basic knowledge of firewall
[reading notes] Figure comparative learning gnn+cl
Applet global style configuration window
一篇文章带你走进cookie,session,Token的世界
[code practice] [stereo matching series] Classic ad census: (4) cross domain cost aggregation
随机推荐
测试老鸟浅谈unittest和pytest的区别
Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
C # image difference comparison: image subtraction (pointer method, high speed)
Uni app implements global variables
Confusion matrix
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
微信小程序获取住户地区信息
fs. Path module
迁移学习和域自适应
. Net service governance flow limiting middleware -fireflysoft RateLimit
What is a firewall? Explanation of basic knowledge of firewall
.NET服务治理之限流中间件-FireflySoft.RateLimit
Codeworks round 681 (Div. 2) supplement
Priority queue (heap)
c语言指针深入理解
Unity skframework framework (XXII), runtime console runtime debugging tool
Kotlin introductory notes (III) kotlin program logic control (if, when)
Deep understanding of C language pointer
2310. 个位数字为 K 的整数之和
Transfer learning and domain adaptation