这题看着简单,其实还挺不容易的,牛客的用例不全,有些错的代码也让通过。。。
class Solution: def maximumSwap(self, num: str) -> str: num = list(num) n = len(num) for i in range(n): index = i for j in range(n-1,i,-1): if num[j] > num[index]: index = j if index!=i: num[i], num[index] = num[index],num[i] break return ''.join(num)