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

Form The Minimum

daco2020 2022. 8. 2. 20:31
반응형

Task

Given a list of digits, return the smallest number that could be formed from these digits, using the digits only once (ignore duplicates).


Notes:

  • Only positive integers will be passed to the function (> 0 ), no negatives or zeros.

    Input >> Output Examples

minValue ({1, 3, 1})  ==> return (13)

Explanation:

(13) is the minimum number could be formed from {1, 3, 1} , Without duplications


minValue({5, 7, 5, 9, 7})  ==> return (579)

Explanation:

(579) is the minimum number could be formed from {5, 7, 5, 9, 7} , Without duplications


minValue({1, 9, 3, 1, 7, 4, 6, 6, 7}) return  ==> (134679)

Explanation:

(134679) is the minimum number could be formed from {1, 9, 3, 1, 7, 4, 6, 6, 7} , Without duplications

 

 

 

 

Solution:

def min_value(digits):
    return int(''.join(map(str,sorted(set(digits)))))

 

 

반응형

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

Small enough? - Beginner  (0) 2022.08.03
Sort the odd  (0) 2022.08.02
Make a function that does arithmetic!  (0) 2022.07.31
Printer Errors  (0) 2022.07.31
Build Tower  (0) 2022.07.29