코딩 테스트/leetCode

[leetCode] 2160. Minimum Sum of Four Digit Number After Splitting Digits (Python)

우주바다 2022. 10. 13. 10:13
728x90

▼ 문제 바로가기 (링크) 

https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/

 

Minimum Sum of Four Digit Number After Splitting Digits - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com


 

class Solution:
    def minimumSum(self, num: int) -> int:
        num = str(num)
        num_list = []
        
        for i in range(4):
            num_list.append(num[i])        
            num_list.sort()

        a = int(num_list[0] + num_list[2])
        b = int(num_list[1] + num_list[3])
        answer = a+b

        return answer

 

Memory Usage: 13.8 MB, less than 57.11% 

 

728x90
반응형