算法(二进制数中1的个数)
来源:互联网 发布:linux启动进入grub 编辑:程序博客网 时间:2024/06/05 15:07
编程之美中,1的个数的几种求法,今天先更新一种我最喜欢的方法。也是感觉很美的算法。
方法一:
package com.robin.other;public class OneNum {public static int oneNum(int data){int count = 0;while(data != 0){data &= (data-1);count++;}return count;}public static void main(String[] args) {int data = 9;int num = oneNum(data);System.out.println("the number of the one in the data is:" + num);}}
0 0
- 算法(二进制数中1的个数)
- 计算二进制数中1的个数的快速算法
- 关于求二进制数中1的个数的算法
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 【算法练习】还是求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- 算法-求二进制数中1的个数
- swift UITabBarItem修改字体颜色和图标颜色
- height、clientHeight、scrollHeight、offsetHeight区别
- ng-repeat
- 产品经理模型建设工具axure
- 黑马程序员——Java编程语言学习总结 –Map集合
- 算法(二进制数中1的个数)
- javascript学习之函数的参数和return语句
- 黑马程序员_java网络编程——UDP传输和TCP传输
- 为什么程序运行不了?求解
- 读取文本数据2.1
- Google C++ 编程风格指南资源
- POJ1845 Sumdiv【因数之和】【二分求等比数列】
- LeetCode 040 Combination SumII
- 4、面向对象