mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
18 lines
457 B
C++
18 lines
457 B
C++
class Solution{
|
|
public:
|
|
char findKthBit(int n, int k){
|
|
string seq = "0";
|
|
for(int i = 1;i<n && seq.length() < k;++i){
|
|
seq+='1';
|
|
string temp = seq;
|
|
for(int j=temp.length()-2;j>=0;--j){
|
|
char invertedBit = (temp[j]=='1')? '0': '1';
|
|
seq+=invertedBit;
|
|
}
|
|
}
|
|
return seq[k-1];
|
|
|
|
|
|
}
|
|
}
|