노력에는 지름길이 없으니까요

LeetCode - 1837. Sum of Digits in Base K (Python ver.) 본문

Python/프로그래머스

LeetCode - 1837. Sum of Digits in Base K (Python ver.)

데건 2024. 9. 16. 13:53
728x90

 

해결일 언어 레벨 테스트명
20240916 Python easy 1837. Sum of Digits in Base K

 

링크 : https://leetcode.com/problems/sum-of-digits-in-base-k/

 

 

 

 

 

n진수로 바꾸는 법.


 

내 코드

class Solution:
    def sumBase(self, n: int, k: int) -> int:
        answer = ''
        while n :
            answer += str(n%k)
            n //= k
        return sum(int(i) for i in answer[::-1])

 

 

 

 

 

728x90
반응형