2243. Calculate Digit Sum of a String

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2243

class Solution:
    def digitSum(self, s: str, k: int) -> str:
        if len(s) <= k:
            return s
        t = []
        while s:
            t.append(str(sum(int(v) for v in s[:k])))
            s = s[k:]
        return self.digitSum(''.join(t), k)