Given a positive integer num consisting only of digits 6 and 9.
Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).
 
Example 1:
Input: num = 9669
Output: 9969
Explanation: 
Changing the first digit results in 6669.
Changing the second digit results in 9969.
Changing the third digit results in 9699.
Changing the fourth digit results in 9666. 
The maximum number is 9969.

Example 2:
Input: num = 9996
Output: 9999
Explanation: Changing the last digit 6 to 9 results in the maximum number.
Example 3:
Input: num = 9999
Output: 9999
Explanation: It is better not to apply any change.
 
Constraints:

1 <= num <= 10^4
num's digits are 6 or 9.

Source: leetcode | Difficulty: EASY
Tags: Mathematics

Greedy algorithms

Starter code: class Solution:
    def maximum69Number (self, num: int) -> int:
        

Solutions:
class Solution:

	def maximum69Number(self, num: int) -> int:
		numString = str(num)
		numLength = len(numString)
		firstIndex = numString.find('6')
		if firstIndex == -1:
			return num
		else:
			return num + 3 * 10 ** (numLength - firstIndex - 1)


class Solution:

	def maximum69Number(self, num: int) -> int:
		res = 0
		li = list(str(num))
		first = -1
		for i in range(len(li)):
			if li[i] == '6':
				first = i
				break
		li[first] = '9'
		return int(''.join(li))


class Solution:

	def maximum69Number(self, num: int) -> int:
		set_max = {9: 9, 99: 99, 999: 999, 9999: 9999, 6: 9, 66: 96, 666: 966, 6666: 9666}
		try:
			return set_max[num]
		except:
			num = str(num)
			for i in range(len(num)):
				if num[i] == '6':
					return int(num[0:i] + '9' + num[i + 1:])


class Solution:

	def maximum69Number(self, num: int) -> int:
		lst = list(map(int, str(num)))
		for i in range(len(lst)):
			if lst[i] == 6:
				lst[i] = 9
				break
		return int(''.join(map(str, lst)))


import functools

class Solution:

	def maximum69Number(self, num: int) -> int:
		lmax = lambda xs: functools.reduce(lambda x, y: x + y, xs)
		print(lmax(['1', '2', '3']))
		str_num = list(str(num))
		for i in range(len(str_num)):
			if int(str_num[i]) == 6:
				str_num[i] = '9'
				break
		str_num = lmax(str_num)
		return int(str_num)


class Solution:

	def maximum69Number(self, num: int) -> int:
		str_num = list(str(num))
		for i in range(len(str_num)):
			if int(str_num[i]) == 6:
				str_num[i] = '9'
				break
		print(str_num)
		str_num = ''.join(str_num)
		return int(str_num)


class Solution:

	def maximum69Number(self, num: int) -> int:
		return int(str(num).replace('6', '9', 1))