博客
关于我
Leetcode 670 最大交换 (贪心思想)
阅读量:234 次
发布时间:2019-03-01

本文共 381 字,大约阅读时间需要 1 分钟。

尝试换最大的数到前面来

class Solution {public:    int maximumSwap(int num) {        string str = to_string(num);        for(int i=0;i
=k){ k = str[j] - '0'; index = j; } } if(k>str[i]-'0'){ swap(str[i],str[index]); return stoi(str); } } return num; }};

 

转载地址:http://vvqv.baihongyu.com/

你可能感兴趣的文章
Mysql之IN 和 Exists 用法
查看>>
MYSQL之REPLACE INTO和INSERT … ON DUPLICATE KEY UPDATE用法
查看>>
MySQL之SQL语句优化步骤
查看>>
MYSQL之union和order by分析([Err] 1221 - Incorrect usage of UNION and ORDER BY)
查看>>
Mysql之主从复制
查看>>
MySQL之函数
查看>>