Calculate Digit Sum of a String LeetCode solution in Python

1
class Solution:
2
def digitSum(self, s: str, k: int) -> str:
3
while len(s) > k:
4
set_3 = [s[i : i + k] for i in range(0, len(s), k)]
5
s = ""
6
for e in set_3:
7
val = 0
8
for n in e:
9
val += int(n)
10
s += str(val)
11
return s

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0