当前位置:网站首页>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
边栏推荐
- Kubedm series-00-overview
- How can the Solon framework easily obtain the response time of each request?
- Common optimization methods
- SSH password free login settings and use scripts to SSH login and execute instructions
- 数仓项目的集群脚本
- Pointnet++ learning
- 浅谈JVM(面试常考)
- 智慧工地“水电能耗在线监测系统”
- Typical use cases for knapsacks, queues, and stacks
- Reflection summary of Haut OJ freshmen on Wednesday
猜你喜欢
[article de jailhouse] jailhouse hypervisor
全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析
Introduction to tools in TF-A
On the characteristics of technology entrepreneurs from Dijkstra's Turing Award speech
Some common problems in the assessment of network engineers: WLAN, BGP, switch
浅谈JVM(面试常考)
剑指 Offer 06.从头到尾打印链表
Wazuh开源主机安全解决方案的简介与使用体验
[jailhouse article] look mum, no VM exits
YOLOv5-Shufflenetv2
随机推荐
Full Permutation Code (recursive writing)
Sword finger offer 58 - ii Rotate string left
Simple knapsack, queue and stack with deque
Sword finger offer 06 Print linked list from beginning to end
[cloud native] record of feign custom configuration of microservices
PC寄存器
2017 USP Try-outs C. Coprimes
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
每日一题-搜索二维矩阵ps二维数组的查找
Daily question - Search two-dimensional matrix PS two-dimensional array search
Bit mask of bit operation
Introduction to convolutional neural network
Fried chicken nuggets and fifa22
Reader writer model
常见的最优化方法
Solution to game 10 of the personal field
A new micro ORM open source framework
卷积神经网络简介
In this indifferent world, light crying
Find a good teaching video for Solon framework test (Solon, lightweight application development framework)