fork download
  1. def next_bigger(n):
  2. num_string = list(str(n))
  3.  
  4. for i, num in enumerate(num_string):
  5.  
  6. if i == len(num_string)-1:
  7. return -1
  8.  
  9. #find two the two numbers one bigger than the other with the minimun order
  10. if num_string[-i-1] > num_string[-i-2]:
  11. aux = num_string[-i-1]
  12.  
  13. #interchange the locations:
  14. num_string[-i-1] = num_string[-i-2]
  15. num_string[-i-2] = aux
  16.  
  17. # create a string from the list
  18. return int("".join(num_string))
  19.  
  20. print(next_bigger(231))
Success #stdin #stdout 0.02s 9200KB
stdin
Standard input is empty
stdout
321