class Solution {
public:
int reverseBits(int num) {
int ans = 0, cnt = 0;
for (int i = 0, j = 0; i < 32; ++i) {
cnt += num >> i & 1 ^ 1;
while (cnt > 1) {
cnt -= num >> j & 1 ^ 1;
++j;
}
ans = max(ans, i - j + 1);
return ans;
};