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-1
th element to return the answer.
code
class Solution {
public:
char kthCharacter(int k) {
= "a";
string s while(s.size() < k) {
int n = s.size();
for (int i = 0; i < n; ++i) {
if (s[i] + 1 - 'a' > 26) {
.push_back('a');
s} else {
.push_back(s[i]+1);
s}
}
}
return s[k-1];
}
};