public static void main(String[] args) { int b[] = {0,3,7,19,12,32,323,212,31,52}; System.out.println(isAndEqationExist(b)); } public static boolean isAndEqationExist(int a[]) { int max = 0; for (int i=0;i<a.length;i++) if(a[i]>max)max = a[i]; int count = 0; while(max>0){ max /=2; count++; } int b[] = new int[a.length]; for (int i=0;i<count;i++) { int countzero = 0; for (int j=0;j<a.length;j++) { if(b[j]!=-1) { int bei = (int) Math.pow(2,i); int nn = a[j]&bei; if(nn==0) { countzero++; }else if(countzero>0) b[j] = -1; }else continue; } for (int j=0;j<a.length;j++) { if(b[j]!=-1) { int bei = (int) Math.pow(2,i); int nn = a[j]&bei; if(nn==0) { countzero++; }else if(countzero>0) b[j] = -1; }else continue; } if(countzero==1)return false; } //搜寻完毕 int index = -1; for (int i=0;i<a.length;i++) if(b[i]==0)index = i; if(index==-1)return false; int sum = 0;boolean fir = true; for (int i=0;i<a.length;i++) { if(i!=index) { if(fir) { sum = sum ^ a[i]; fir = false; }else { sum &= a[i]; } } } if(sum==a[index])return true; return false; }
点赞 评论

相关推荐

死在JAVA的王小美:哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈,我也是,让我免了一轮,但是硬气拒绝了
点赞 评论 收藏
分享
头像
11-09 17:30
门头沟学院 Java
TYUT太摆金星:我也是,好几个华为的社招找我了
点赞 评论 收藏
分享
牛客网
牛客企业服务