1945. Sum of Digits of String After Convert

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1945

class Solution:
    def getLucky(self, s: str, k: int) -> int:
        s = ''.join(str(ord(c) - ord('a') + 1) for c in s)
        for _ in range(k):
            t = sum(int(c) for c in s)
            s = str(t)
        return int(s)