当前位置:网站首页>剑指offer基础版 --- 第21天
剑指offer基础版 --- 第21天
2022-07-31 05:09:00 【米兰的小红黑】
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int x = 0;
while(n != 0){
if((n & 1) == 1){
x++;
n = n >>> 1;
}else{
n = n >>> 1;
}
}
return x;
}
}
class Solution {
public int add(int a, int b) {
int res = a;
while(b != 0){
res = a ^ b;
b = (a & b) << 1;
a = res;
}
return res;
}
}
边栏推荐
猜你喜欢
SQL injection of DVWA
MySQL8--Windows下使用压缩包安装的方法
面试Redis 高可靠性|主从模式、哨兵模式、Cluster集群模式
剑指offer专项突击版 ---- 第1天
目标检测学习笔记
SQL row-column conversion
mysql使用on duplicate key update批量更新数据
Minesweeper game (written in c language)
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
With MVC, why DDD?
随机推荐
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
C语言如何分辨大小端
Duplicate entry 'XXX' for key 'XXX.PRIMARY' solution.
STM32 - DMA
Input length must be multiple of 8 when decrypting with padded cipher
numpy和pytorch中的元素拼接操作:stack,concatenat,cat
C语言指针详解
Simple read operation of EasyExcel
SQL statement to range query time field
110道 MySQL面试题及答案 (持续更新)
Refinement of the four major collection frameworks: Summary of List core knowledge
Pytorch教程Introduction中的神经网络实现示例
账号或密码多次输入错误,进行账号封禁
Typec手机有线网卡网线转网口转接口快充方案
TOGAF之架构标准规范(一)
【一起学Rust】Rust学习前准备——注释和格式化输出
剑指offer专项突击版 ---- 第1天
Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
剑指offer专项突击版 ---- 第 6 天
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work