Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
17 lines (15 sloc) 318 Bytes
def ms(s):
if not s:
return ''
v = max(s)
if s[0] == v:
return s[0] + ms(s[1:])
m = s.rfind(v)
return s[m] + s[1:m] + s[0] + s[m+1:]
class Solution:
def maximumSwap(self, num):
"""
:type num: int
:rtype: int
"""
return int(ms(str(num)))