leetCode868

mac2025-01-27  35

class Solution { public: int binaryGap(int N) { long long x = -1,y = -1; long long i = 0; int ans = -1; while(N) { if(N%2 == 1) { x = y; y = i; //cout<<y-x<<endl; if(x!=-1 && y!=-1) ans = ans>y-x?ans : y-x; } N/=2; i++; } return ans != -1 ? ans:0; } };

 

最新回复(0)