Created
July 30, 2023 05:02
-
-
Save modos/19bca059749111590716f0febb89624c to your computer and use it in GitHub Desktop.
باقر مخالف است
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional, List | |
def get_smaller_digit(sorted_digits: List[str], bigger_than: str) -> Optional[str]: | |
for i in range(len(sorted_digits)): | |
if sorted_digits[i] > bigger_than: | |
return sorted_digits[i] | |
return None | |
def solve(number: str) -> str: | |
for i in range(len(number) - 2, -1, -1): | |
remain_digits = sorted(number[i:]) | |
smaller_digit = get_smaller_digit(remain_digits, number[i]) | |
if smaller_digit is None: | |
continue | |
remain_digits.remove(smaller_digit) | |
return number[0:i] + smaller_digit + ''.join(remain_digits) | |
return '0' | |
def main(): | |
number = input() | |
result = solve(number) | |
print(result) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment