当前位置:网站首页>556. The next larger element III
556. The next larger element III
2022-07-03 14:22:00 【anieoo】
Original link :556. Next bigger element III
solution:
class Solution {
public:
int nextGreaterElement(int n) {
string s = to_string(n); // Process numeric programming strings
int k = s.size() - 1;
while(k > 0 && s[k - 1] >= s[k]) k--; // From back to front, if it is in ascending order, it is the largest number
if(!k) return -1; // If the whole string is in ascending order from back to front , Nothing is bigger than it
int t = k;
while(t + 1 < s.size() && s[t + 1] > s[k - 1]) t++; // from k + 1 Start , Find the first match s[k - 1] Big numbers
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;
}
};边栏推荐
- Exercise 9-1 time conversion
- Leetcode(4)——寻找两个正序数组的中位数
- LNMP环境mail函数不能发送邮件解决
- String reverse order
- Webpage connection database ~ simple implementation of addition, deletion, modification and query complete code
- NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
- 7-23 currency conversion (using array conversion)
- Find specified characters
- 分布式事务(Seata) 四大模式详解
- Exercise 10-6 recursively find Fabonacci sequence
猜你喜欢

x86汇编语言-从实模式到保护模式 笔记

Redis: redis data structure and key operation commands

八大排序

Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions

Understand the application scenario and implementation mechanism of differential segment

【北大青鸟昌平校区】互联网行业中,哪些岗位越老越吃香?

Doris学习笔记之数据表的创建

Redis:字符串类型数据的操作命令

Redis:Redis的数据结构、key的操作命令

Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
随机推荐
Simulated access
TS code automatically generates JS
concat和concat_ws()区别及group_concat()和repeat()函数的使用
JS shift operators (< <,> > and > > >)
Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not
Invalid Z-index problem
7-14 sum integer segments (C language)
剑指 Offer 28. 对称的二叉树
Recent learning summary
How Facebook moves instagram from AWS to its own server
Leetcode (4) -- find the median of two positively ordered arrays
MySQL multi table query subquery
6-9 statistics of single digits (15 points)
中国PETG市场预测及战略研究报告(2022版)
JS input number and standard digit number are compared. The problem of adding 0 to 0
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
SSH访问控制,多次失败登录即封掉IP,防止暴力破解
Sendmail无法发送邮件及发送过慢解决
7-6 mixed type data format input