Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- You are given an integer n consisting of digits 1, 2, and 3 and you can flip one digit to a 3.
- Return the maximum number you can make.
- Example 1
- Input
- n = 123
- Output
- 323
- '''
- def solve(n):
- nums = str(n)
- numbers = list()
- for i in range(len(nums)):
- numbers.append(nums[i])
- for i in range(len(numbers)):
- if numbers[i] != '3':
- numbers[i] = '3'
- break
- newNums = ""
- for i in range(len(numbers)):
- newNums += str(numbers[i])
- return int(newNums)
- # MAIN FUNCTION
- print("123 ----> " + str(solve(123)))
- print("321 ----> " + str(solve(321)))
- print("332 ----> " + str(solve(331)))
- print("333 ----> " + str(solve(333)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement