【剑指offer】七,二进制表示中1的个数

it2022-05-05  155

题目描述

输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。   1 public class Solution { 2 public int NumberOf1(int n) { 3 int count = 0 ; 4 while(n!=0){ 5 count++ ; 6 n = n&(n-1) ; 7 } 8 return count ; 9 }

 

转载于:https://www.cnblogs.com/huntertoung/p/4760034.html


最新回复(0)