Algorithm/Leetcode, Lintcode, HackerRank, etc.
2243. Calculate Digit Sum of a String
Roiei
2022. 4. 29. 19:50
반응형
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
반응형