int binaryGap(int n){ int max=0, pre=-1, cnt=0; while(n){ if((n&1) == 1 ){ if(pre>=0 && cnt-pre > max) max=cnt-pre; pre=cnt; } cnt++; n>>=1; } return max; }
int binaryGap(int n){ int max=0, pre=-1, cnt=0; while(n){ if((n&1) == 1 ){ if(pre>=0 && cnt-pre > max) max=cnt-pre; pre=cnt; } cnt++; n>>=1; } return max; }
(N&1) ==0位运算的优先级好低 & 低于== 需要加括号#include <iostream>using namespace std;#
g a, String b) { //较长字符串和...
868. Binary Gap*https://leetcode.com/problems/binary-gap/
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M