当前位置:网站首页>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;
}
}
边栏推荐
- [beauty of algebra] solution method of linear equations ax=0
- Alibaba's ten-year test brings you into the world of APP testing
- C # image difference comparison: image subtraction (pointer method, high speed)
- nodejs_ 01_ fs. readFile
- Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
- OpenGL - Model Loading
- STM32简易多级菜单(数组查表法)
- Introduction Guide to stereo vision (7): stereo matching
- Unity skframework framework (XXIII), minimap small map tool
- Understanding of smt32h7 series DMA and DMAMUX
猜你喜欢

Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)

Principle and performance analysis of lepton lossless compression
![Rebuild my 3D world [open source] [serialization-1]](/img/74/b6253845b43bc18f425d57695fba7c.jpg)
Rebuild my 3D world [open source] [serialization-1]

Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
![[ManageEngine] how to make good use of the report function of OpManager](/img/15/dc15e638ae86d6cf1d5b989fe56611.jpg)
[ManageEngine] how to make good use of the report function of OpManager

【阅读笔记】图对比学习 GNN+CL
![一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]](/img/c4/27ae0d259abc4e61286c1f4d90c06a.png)
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]

LeetCode 556. 下一个更大元素 III
![[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b](/img/ee/8e07e2dd89bed63ff44400fe1864a9.jpg)
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b

Unity SKFramework框架(二十三)、MiniMap 小地图工具
随机推荐
项目实战 | Excel导出功能
VS Code问题:长行的长度可通过 “editor.maxTokenizationLineLength“ 进行配置
Uni app implements global variables
Applet (use of NPM package)
[code practice] [stereo matching series] Classic ad census: (5) scan line optimization
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
Summary and Reflection on issues related to seq2seq, attention and transformer in hands-on deep learning
MYSQL 对字符串类型排序不生效问题
np.allclose
Jenkins Pipeline 方法(函数)定义及调用
OpenGL - Coordinate Systems
Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
Node collaboration and publishing
【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
An article takes you into the world of cookies, sessions, and tokens
浅谈Label Smoothing技术
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
STM32 simple multi-level menu (array table lookup method)
深入浅出PyTorch中的nn.CrossEntropyLoss
阿里十年测试带你走进APP测试的世界