HTMLify

LeetCode - Sum of Digits of String After Convert - Python
Views: 24 | Author: abh
class Solution:
    def getLucky(self, s: str, k: int) -> int:
        n = ""
        for c in s:
            n += str(ord(c)-96)
        for _ in range(k):
            s = 0
            for n_ in n:
                s += int(n_)
            n = str(s)
        return int(n)

Comments