Skip to content

Instantly share code, notes, and snippets.

@izumigoto
Created January 2, 2024 14:08
Show Gist options
  • Save izumigoto/adbddbd5b9b32d2193aa6e6f16f94243 to your computer and use it in GitHub Desktop.
Save izumigoto/adbddbd5b9b32d2193aa6e6f16f94243 to your computer and use it in GitHub Desktop.
A code to find the largest number by only changing a digit
numbers = [69, 699, 69, 96666, 699]
def find_largest_number(numbers):
max_number = float('-inf')
for num in numbers:
num_str = str(num)
for i in range(len(num_str)):
temp_num = int(num_str[:i] + '9' + num_str[i+1:])
max_number = max(max_number, temp_num)
return max_number
largest_number = find_largest_number(numbers)
print("Largest Number:", largest_number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment