Skip to content
LC-1844 Easy LeetCode

1844. Replace All Digits with Characters

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 82% Topics: String
View full problem on LeetCode

Reading material

Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def replaceDigits(self, s):
        """
        :type s: str
        :rtype: str
        """
        return "".join(chr(ord(s[i-1])+int(s[i])) if i%2 else s[i] for i in xrange(len(s)))

Solution from kamyu104/LeetCode-Solutions · MIT

Similar questions