diff --git a/1945-sum-of-digits-of-string-after-convert/1945-sum-of-digits-of-string-after-convert.py b/1945-sum-of-digits-of-string-after-convert/1945-sum-of-digits-of-string-after-convert.py new file mode 100644 index 0000000..6ba6588 --- /dev/null +++ b/1945-sum-of-digits-of-string-after-convert/1945-sum-of-digits-of-string-after-convert.py @@ -0,0 +1,20 @@ +class Solution(object): + def getLucky(self, s, k): + """ + :type s: str + :type k: int + :rtype: int + """ + + string_to_transform = "" + + for letter in s: + string_to_transform += str(ord(letter) - ord('a') + 1) + + for i in range(k): + curr_sum = 0 + for digit in string_to_transform: + curr_sum += int(digit) + string_to_transform = str(curr_sum) + + return int(string_to_transform) \ No newline at end of file