Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def nextGreat(numlist,N):
- for i in range(N-1,0,-1):
- if numlist[i] > numlist[i-1]:
- break
- answer = numlist[i-1]
- small = i
- for j in range(i+1,N):
- if numlist[j] > answer and numlist[j] < numlist[small]:
- small = j
- numlist[small],numlist[i-1] = numlist[i-1], numlist[small]
- answer=int(str(''.join(map(str,numlist)))[:i])
- numlist = sorted(numlist[i:])
- for j in range(N-i):
- answer = answer * 10 + int(numlist[j])
- print(answer)
- input1=3
- input2="182"
- numlist = list(input2)
- nextGreat(numlist, input1)
Advertisement
Add Comment
Please, Sign In to add comment