Skip to content

Latest commit

 

History

History
19 lines (17 loc) · 441 Bytes

1945.md

File metadata and controls

19 lines (17 loc) · 441 Bytes

1945. Sum of Digits of String After Convert

Solution 1 (time O(n), space O(1))

class Solution(object):
    def getLucky(self, s, k):
        """
        :type s: str
        :type k: int
        :rtype: int
        """
        ans = ""
        for c in s:
            ans += str(ord(c) - ord('a') + 1)
        for _ in range(k):
            ans = str(sum(int(c) for c in ans))
        return int(ans)