3304: Find-the-K-th-Character-in-String-Game-I
Easy


table of contents

Since the constraints are so small, we can technically afford to just simulate operations until we have a s with size greater than k. Then, we can simply just index for the k-1th element to return the answer.

code

class Solution {
public:
    char kthCharacter(int k) {
        string s = "a";
        while(s.size() < k) {
            int n = s.size();
            for (int i = 0; i < n; ++i) {
                if (s[i] + 1 - 'a' > 26) {
                    s.push_back('a');
                } else {
                    s.push_back(s[i]+1);
                }
            }
        }
        return s[k-1];
    }
};

complexity