2025-08-02 15:04:04 +0000 UTC

Decrypt String from Alphabet to Integer Mapping

Code

class Solution:
    def freqAlphabets(self, s: str) -> str:
        res = []
        length = len(s)
        i = 0
        while i < length:
            if i + 2 <  length and s[i + 2] == "#":
                res.append(chr(int(s[i:i+2]) + 97 - 1))
                i += 3
            else:
                res.append(chr(int(s[i]) + 97 - 1))
                i += 1
        return "".join(res)