题解 | #bit位数#

bit位数

http://www.nowcoder.com/practice/daf9032926614dab91ca624a7759a868

import java.util.*;
public class Main {
    public static int countDif(int m, int n) {
        int cnt = 0;
        while(m != 0 || n != 0) {
            if((m & 1) != (n & 1)) {
                cnt++;
            }
            m >>= 1;
            n >>= 1;
        }
        return cnt;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        System.out.println(countDif(m, n));
    }
}
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务