Skip to content

Commit 0720348

Browse files
committed
Time: 22 ms (47.94%), Space: 58.7 MB (42.78%) - LeetHub
1 parent 7f5140d commit 0720348

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
char findKthBit(int n, int k) {
4+
string str = "0";
5+
for (int i = 2; i <= n; i++) {
6+
str = str + "1" + rev(flip(str));
7+
}
8+
return str[k - 1];
9+
}
10+
string flip(string str) {
11+
for (auto& i : str) {
12+
if (i == '0') i = '1';
13+
else i = '0';
14+
}
15+
return str;
16+
}
17+
string rev(string str) {
18+
reverse(str.begin(), str.end());
19+
return str;
20+
}
21+
};

0 commit comments

Comments
 (0)