当前位置:网站首页>JZ15 二进制中1的个数
JZ15 二进制中1的个数
2022-08-02 15:35:00 【syc596】
JZ15 二进制中1的个数
二进制中1的个数_牛客题霸_牛客网 (nowcoder.com)
//11
import java.util.*;
public class Solution {
public int NumberOf1(int n) {
int count=0;
while(n!=0){
if((n&1)==1){
count++;
}
n=n>>>1;//无符号右移
}
return count;
}
}
// //n&(n-1)
// import java.util.*;
// public class Solution {
// public int NumberOf1(int n) {
// int count=0;
// while(n!=0){
// n=n&(n-1);
// count++;
// }
// return count;
// }
// }
边栏推荐
猜你喜欢
随机推荐
CefSharp practical demonstration
“行泊一体”的火爆与现实困境
Qt | QWidget 的一些总结
How to use PHP to implement lexical analyzer and custom language
微信小程序:Framework inner error FLOW_CREATE_NODE
禅道16.5升级17.3
莫比乌斯反演学习笔记
tiup mirror modify
(LinkedList与链表) 和 (ArrayList与顺序表)的区别
ROS人机交互软件
Go-6-常用命令-go包管理问题-两个路径-GO111MODULE
管理软件开发 管理软件定制开发流程
WWW'22 推荐系统论文之序列推荐篇
ICML/ICLR'22 推荐系统论文梳理
Qt | 文件操作 QFile
20 Lectures on Disassembly of Multi-merchant Mall System Functions-Platform Distribution Overview
Basic management of mysql database in Linux system
redis学习四redis消息订阅、pipeline、事务、modules、布隆过滤器、缓存LRU
uWSGI看这几篇就够了
系统存储的基本管理--挂载,分区,用户配额