当前位置:网站首页>Daily question-leetcode556-next larger element iii-string-double pointer-next_ permutation
Daily question-leetcode556-next larger element iii-string-double pointer-next_ permutation
2022-07-04 21:24:00 【Li Fan, hurry up】
Note:
Look from the back to the front , Find the first smaller number , Then put him in the back Exchange the smallest number larger than him
And then change all the positions behind him reverse Again , Just return to the answer
The code is as follows :
class Solution {
public:
int nextGreaterElement(int n) {
string s = to_string(n);
int k = s.size() - 1;
while(k && 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 ++;
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;
}
};
边栏推荐
- 杰理之AD 系列 MIDI 功能说明【篇】
- 【Try to Hack】宽字节注入
- Day24:文件系统
- 华为ensp模拟器 DNS服务器的配置
- 冰河的海报封面
- 2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
- 每日一题-LeetCode1200-最小绝对差-数组-排序
- [server data recovery] a case of RAID5 data recovery stored in a brand of server
- NetWare r7000 Merlin system virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements. Solution, is it necessary to create virtual memory??
- What are the functional modules of RFID warehouse management system solution
猜你喜欢

6月“墨力原创作者计划”获奖名单公布!邀您共话国产数据库

c语言函数形参自增自减情况分析

每日一题-LeetCode556-下一个更大元素III-字符串-双指针-next_permutation

D3.js+Three.js数据可视化3d地球js特效

Redis:Redis配置文件相关配置、Redis的持久化

Huawei ENSP simulator configures ACL access control list

华为ensp模拟器实现通信安全(交换机)

【1200. 最小絕對差】

What are the functional modules of RFID warehouse management system solution

SolidWorks工程图添加材料明细表的操作
随机推荐
Jerry's ad series MIDI function description [chapter]
Golang中UTF编码和字符集
IIC (STM32)
IIC (STM32)
HMS Core 机器学习服务
【微信小程序】协同工作与发布
Actual combat simulation │ JWT login authentication
华为ensp模拟器实现通信安全(交换机)
测试用例 (TC)
2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
冰河的海报封面
【1200. 最小絕對差】
Huawei ENSP simulator layer 3 switch
迈动互联中标北京人寿保险
ApplicationContext 与 BeanFactory 区别(MS)
解读创客教育中的各类智能化组织发展
Remember to build wheels repeatedly at one time (the setting instructions of obsidian plug-in are translated into Chinese)
Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)
Liu Jincheng won the 2022 China e-commerce industry innovation Figure Award
HMS Core 统一扫码服务