public class Solution { public int NumberOf1(int n) { int count = 0; while (n != 0) { // n < 0,则符号位为1 if (n < 0) { ++ count; } // 左移一位 n <<= 1; } return count; } }
public class Solution { public int NumberOf1(int n) { int count = 0; while (n != 0) { // n < 0,则符号位为1 if (n < 0) { ++ count; } // 左移一位 n <<= 1; } return count; } }