Answers for "find next greater number with same digits"

-1

find next greater number with same digits

def findnext(ii):
    iis=list(map(int,str(ii)))
    for i in reversed(range(len(iis))):
        if i == 0: return ii
        if iis[i] > iis[i-1] :
            break        
    left,right=iis[:i],iis[i:]
    for k in reversed(range(len(right))):
        if right[k]>left[-1]:
           right[k],left[-1]=left[-1],right[k]
           break
    return int("".join(map(str,(left+sorted(right)))))
Posted by: Guest on August-10-2020

Code answers related to "find next greater number with same digits"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language