Skip to content

Commit 3394b9b

Browse files
committed
Time: 0 ms (100.00%), Space: 40.7 MB (73.93%) - LeetHub
1 parent 921040e commit 3394b9b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public char findKthBit(int n, int k) {
3+
int flip = 0, l = (1 << n) - 1;
4+
while (k > 1) {
5+
if (k == l / 2 + 1)
6+
return flip == 0 ? '1' : '0';
7+
if (k > l / 2) {
8+
k = l + 1 - k;
9+
flip ^= 1;
10+
}
11+
l /= 2;
12+
}
13+
return flip == 0 ? '0' : '1';
14+
}
15+
}

0 commit comments

Comments
 (0)