mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 03:27:07 +00:00
Time: 5 ms (73.71%), Space: 12.4 MB (82.33%) - LeetHub
This commit is contained in:
+20
@@ -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)
|
||||
Reference in New Issue
Block a user