首页 > 其他分享 >#yyds干货盘点# 名企真题专题:懂二进制

#yyds干货盘点# 名企真题专题:懂二进制

时间:2022-12-19 20:02:07浏览次数:34  
标签:count yyds 名企 真题 int 示例 二进制 返回值 public

1.简述:

描述

世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么?

示例1

输入:

3,5

复制

返回值:

2

说明:

3的二进制为11,5的二进制为101,总共有2位不同
示例2

输入:

1999,2299

返回值:

7

2.代码实现:

public class Solution {
public int countBitDiff (int m, int n) {
int c = m^n;
int count = 0;
while(c != 0){
count += c & 1;
c = c >> 1;
}
return count;
}
}

标签:count,yyds,名企,真题,int,示例,二进制,返回值,public
From: https://blog.51cto.com/u_15488507/5953777

相关文章