LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.1MB, accepted 2025-12-31.

python
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)

Source