관리 메뉴

솜씨좋은장씨

[leetCode] 1945. Sum of Digits of String After Convert (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 1945. Sum of Digits of String After Convert (Python)

솜씨좋은장씨 2022. 1. 27. 00:54
728x90
반응형

코딩 1일 1문제! 오늘의 문제는 leetCode의 Sum of Digits of String After Convert 입니다.

 

Sum of Digits of String After Convert - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

👨🏻‍💻 코드 ( Solution )

class Solution:
    def getLucky(self, s: str, k: int) -> int:
        alphabet_list = list(s)
        
        convert_str = []
        
        for alpha in alphabet_list:
            convert_str.append(str(ord(alpha) - ord('a') + 1))
            
        convert_str = "".join(convert_str)
        
        transform_num = list(convert_str)
        
        for i in range(k):
            transform_num = sum(list(map(int, transform_num)))
            if i < k-1:
                transform_num = list(str(transform_num))
                
        return transform_num

 

GitHub - SOMJANG/CODINGTEST_PRACTICE: 1일 1문제 since 2020.02.07

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

Comments