From 6ca9045dbb8c397dda7568c580b072db903d4cec Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Tue, 9 Sep 2025 15:26:54 -0400 Subject: [PATCH] Time: 5 ms (73.71%), Space: 12.4 MB (82.33%) - LeetHub --- ...5-sum-of-digits-of-string-after-convert.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 1945-sum-of-digits-of-string-after-convert/1945-sum-of-digits-of-string-after-convert.py 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