//求一个整数的二进制串中1的个数

public int hammingWeight(int n) { String b_str = Integer.toBinaryString(n); int b_count = 0; for(int i=0; i<b_str.length(); i++) { if(b_str.charAt(i) == '1') { b_count ++; } } return b_count; }

 

相关文章:

  • 2022-03-07
  • 2022-01-01
  • 2021-06-16
  • 2021-07-02
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2021-08-30
  • 2021-09-22
  • 2021-05-19
  • 2021-09-09
  • 2021-08-22
  • 2022-01-09
  • 2022-01-11
相关资源
相似解决方案