본문 바로가기
python-algorithm

leetcode 1945. Sum of Digits of String After Convert

by 무적김두칠 2022. 7. 7.

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
    def getLucky(self, s: str, k: int-> int:
            str_num=''
            for i in s:
                str_num+=str(ord(i)-96)
            int_num=0
            for _ in range(k):
                for i in str_num:
                    int_num+=int(i)
                str_num=str(int_num)
                int_num=0
 
            return(int(str_num))
cs

 

반응형

댓글