当前位置:网站首页>Daily question 1342 Number of operations to change the number to 0
Daily question 1342 Number of operations to change the number to 0
2022-07-05 05:42:00 【A big pigeon】
topic : Given num, If the current number is even , You need to divide it by 2 ; otherwise , subtract 1 . Ask for general num become 0 Required times .
Explain : Directly according to the meaning of the topic , Bit operation can improve computational efficiency
class Solution:
def numberOfSteps(self, num: int) -> int:
step = 0
while num:
if num&1: #num It's amazing , Equivalent to num%2 ==1
num -= 1
else:
num = num>>1 # Equivalent to num // 2
step += 1
return step
边栏推荐
猜你喜欢

Some common problems in the assessment of network engineers: WLAN, BGP, switch

第六章 数据流建模—课后习题

Smart construction site "hydropower energy consumption online monitoring system"

Using HashMap to realize simple cache

Light a light with stm32

剑指 Offer 05. 替换空格

sync.Mutex源码解读

Implement an iterative stack

Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module

剑指 Offer 04. 二维数组中的查找
随机推荐
Maximum number of "balloons"
2022 pole technology communication arm virtual hardware accelerates the development of Internet of things software
记录QT内存泄漏的一种问题和解决方案
sync.Mutex源码解读
Wazuh开源主机安全解决方案的简介与使用体验
[practical skills] how to do a good job in technical training?
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
In this indifferent world, light crying
数仓项目的集群脚本
26、 File system API (device sharing between applications; directory and file API)
卷积神经网络简介
High precision subtraction
Over fitting and regularization
Pointnet++学习
Add level control and logger level control of Solon logging plug-in
Smart construction site "hydropower energy consumption online monitoring system"
剑指 Offer 04. 二维数组中的查找
ssh免密登录设置及使用脚本进行ssh登录并执行指令
Using HashMap to realize simple cache
EOJ 2021.10 E. XOR tree