Advertisement
makispaiktis

BinarySearchIO - 123 Flip Number

Aug 23rd, 2020 (edited)
1,410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. '''
  2. You are given an integer n consisting of digits 1, 2, and 3 and you can flip one digit to a 3.
  3. Return the maximum number you can make.
  4. Example 1
  5. Input
  6. n = 123
  7. Output
  8. 323
  9. '''
  10.  
  11. def solve(n):
  12.     nums = str(n)
  13.     numbers = list()
  14.     for i in range(len(nums)):
  15.         numbers.append(nums[i])
  16.     for i in range(len(numbers)):
  17.         if numbers[i] != '3':
  18.             numbers[i] = '3'
  19.             break
  20.     newNums = ""
  21.     for i in range(len(numbers)):
  22.         newNums += str(numbers[i])
  23.     return int(newNums)
  24.  
  25.  
  26. # MAIN FUNCTION
  27. print("123 ----> " + str(solve(123)))
  28. print("321 ----> " + str(solve(321)))
  29. print("332 ----> " + str(solve(331)))
  30. print("333 ----> " + str(solve(333)))
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement