先把 转换成二进制数组,然后求最长平台即可。
#include <bits/stdc++.h>
using namespace std ;
long long n , a[100] , len , cnt , maxn ;
int main() {
cin >> n ;
while(n) {
a[++ len] = n % 2 ;
n /= 2 ;
}
for(int i = 1 ; i <= len ; i ++) {
if(a[i]) {
cnt ++ ;
} else {
maxn = max(maxn , cnt) ;
cnt = 0 ;
}
}
cout << max(maxn , cnt) ;
return 0 ;
}
- 时间复杂度:。
- 空间复杂度:。
暂无评论