当前位置:网站首页>556. 下一个更大元素 III
556. 下一个更大元素 III
2022-07-03 13:43:00 【anieoo】
原题链接:556. 下一个更大元素 III
solution:
class Solution {
public:
int nextGreaterElement(int n) {
string s = to_string(n); //将数字编程字符串处理
int k = s.size() - 1;
while(k > 0 && s[k - 1] >= s[k]) k--; //从后往前如果是升序则是最大的数字
if(!k) return -1; //如果整个字符串从后往前都是升序的,没有比它更大的
int t = k;
while(t + 1 < s.size() && s[t + 1] > s[k - 1]) t++; //从k + 1开始,找打第一个比s[k - 1]大的数字
swap(s[k - 1], s[t]);
reverse(s.begin() + k,s.end());
long long res = stoll(s);
if(res > INT_MAX) return -1;
return res;
}
};边栏推荐
- simpleParallax. JS (create poor visual effects for website pictures)
- 信创产业现状、分析与预测
- Qt学习20 Qt 中的标准对话框(中)
- Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
- Example analysis of QT learning 18 login dialog box
- Invalid Z-index problem
- Programmable logic device software testing
- 1px problem of mobile terminal
- Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
- [clean up the extraordinary image of Disk C]
猜你喜欢

QT learning 17 dialog box and its types

7-9 find a small ball with a balance

JS input number and standard digit number are compared. The problem of adding 0 to 0

八大排序

Uniapp tips - scrolling components

【吉林大学】考研初试复试资料分享

Programmable logic device software testing

核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)

Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)

allegro,orcad, net alias,port,off-page connector之间的异同点和如何选取
随机推荐
3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
Exercise 6-1 classify and count the number of characters
Raft 协议
中国PETG市场预测及战略研究报告(2022版)
C library function - qsort()
js 2023. String pair equal to the target string after connection
Exercise 8-8 moving letters
Vite project commissioning
八大排序
7-10 calculate salary
Qt学习18 登录对话框实例分析
Spring cup eight school league
Exercise 9-1 time conversion
牛客网:过河卒
[combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
FPGA测试方法以Mentor工具为例
JS Part III
JS new challenges
Back to top implementation
fpga阻塞赋值和非阻塞赋值