Binary Gap
<-E 868> Binary Gap
class Solution {
public:
int binaryGap(int n) {
string str = bitset<64>(n).to_string();
int dist = 0, pre = -1;
for (auto i = 0; i < 64; i++)
{
if (str[i] != '0')
{
if (pre == -1)
pre = i;
else
dist = max(dist, i - pre), pre = i;
}
}
return dist;
}
};