2025-08-24 10:10:51 +0000 UTC

Find the K-th Character in String Game I

Code

class Solution:
    def kthCharacter(self, k: int) -> str:
        res = 0
        while k != 1:
            ln = k.bit_length() - 1
            if (1 << ln) == k:
                ln -= 1
            k -= 1 << ln
            res += 1
        return chr(res + 97)