본문 바로가기
python-algorithm

leetcode 1844. Replace All Digits with Characters

by 무적김두칠 2022. 3. 15.

1
2
3
4
5
6
7
class Solution:
    def replaceDigits(self, s: str-> str:
        ans=''
        for i in range(len(s)):
            if s[i].isalpha(): ans+=s[i]
            if s[i].isdigit(): ans+=chr(ord(s[i-1])+int(s[i]))
        return ans                
cs
반응형

댓글