|
亲!马上注册或者登录会查看更多内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
虽然没有难度还是WA了2次,需要注意:(1)swap之后别忘了swap back,要细心呐
(2)结果要初始化为原值,表示swap the ith digit with the ith dight,由于题目说是by swapping any two digits,two还加粗强调,就以为必须交换一次,就初始化为了INT_MIN,然后又WA了
- class Solution {
- public:
- int maximizeResult(int n) {
- auto s = to_string(n);
- int res = n;
- for(int i = 0; i < s.size(); ++i){
- for(int j = i+1; j < s.size(); ++j){
- swap(s【i】, s[j]);
- res = max(res, stoi(s));
- swap(s【i】, s[j]);
- }
- }
- return res;
- }
- };
复制代码
|
|