2243. Calculate Digit Sum of a String

2022. 4. 29. 19:50Algorithm/Leetcode, Lintcode, HackerRank, etc.

    목차
반응형
class Solution:
    def digitSum(self, s: str, k: int) -> str:
        while len(s) > k:
            i = 0
            next = ''
            while i < len(s):
                next += str(sum([int(ch) for ch in s[i:min(i + k, len(s))]]))
                i += k
            s = next
        
        return s
반응형