当前位置:网站首页>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;
}
};边栏推荐
- Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
- LNMP环境mail函数不能发送邮件解决
- JS matrix zero
- Exercise 10-1 calculate the sum of 1 to n using recursive functions
- How to bold text in AI
- Exercise 6-2 using functions to sum special A-string sequences
- Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
- Solution to failure or slow downloading of electron when electron uses electron builder to package
- Find the sum of the elements of each row of the matrix
- Statistical capital consonants
猜你喜欢
随机推荐
Too many files with unapproved license
Solution to failure or slow downloading of electron when electron uses electron builder to package
Add ZABBIX calculation type itemcalculated items
【北大青鸟昌平校区】互联网行业中,哪些岗位越老越吃香?
7-15 calculation of PI
一文了解微分段应用场景与实现机制
simpleParallax. JS (create poor visual effects for website pictures)
String substitution
Reflection -- basic usage
虽然不一定最优秀,但一定是最努力的!
Raft 协议
7-19 check denomination (solve binary linear equation)
concat和concat_ws()区别及group_concat()和repeat()函数的使用
Exercise 8-8 moving letters
Recent learning summary
7-14 sum integer segments (C language)
Fabric. JS document
Exercise 8-2 calculate the sum and difference of two numbers
How Facebook moves instagram from AWS to its own server
适用于XP的DDK









