1954. Replace All Digits with Characters
My accepted Python solution to LeetCode problem 1954, Replace All Digits with Characters, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.1MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.1MB, accepted 2025-12-31.
class Solution:
def replaceDigits(self, s: str) -> str:
result = list(s)
for i in range(1, len(s), 2):
result[i] = chr(ord(s[i-1]) + int(s[i]))
return ''.join(result)