나는 이렇게 학습한다/Algorithm & SQL

Descending Order

daco2020 2022. 8. 5. 07:28
반응형

Your task is to make a function that can take any non-negative integer as an argument and return it with its digits in descending order. Essentially, rearrange the digits to create the highest possible number.

Examples:

Input: 42145 Output: 54421

Input: 145263 Output: 654321

Input: 123456789 Output: 987654321

 

Solution:

def descending_order(num):
    return int("".join(sorted([i for i in str(num)], reverse=True)))

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Factorial  (0) 2022.08.07
Count the Digit  (0) 2022.08.05
Small enough? - Beginner  (0) 2022.08.03
Sort the odd  (0) 2022.08.02
Form The Minimum  (0) 2022.08.02