当前位置:网站首页>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
边栏推荐
- 【Jailhouse 文章】Jailhouse Hypervisor
- kubeadm系列-02-kubelet的配置和启动
- Haut OJ 1401: praise energy
- 剑指 Offer 05. 替换空格
- 剑指 Offer 35.复杂链表的复制
- Control Unit 控制部件
- Codeforces Round #716 (Div. 2) D. Cut and Stick
- 2022 极术通讯-Arm 虚拟硬件加速物联网软件开发
- Solution to game 10 of the personal field
- AtCoder Grand Contest 013 E - Placing Squares
猜你喜欢
Codeforces round 712 (Div. 2) d. 3-coloring (construction)
Web APIs DOM node
A new micro ORM open source framework
[jailhouse article] jailhouse hypervisor
Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module
In this indifferent world, light crying
剑指 Offer 06.从头到尾打印链表
sync.Mutex源码解读
Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
SAP method of modifying system table data
随机推荐
SAP-修改系统表数据的方法
Palindrome (csp-s-2021-palin) solution
Introduction et expérience de wazuh open source host Security Solution
Add level control and logger level control of Solon logging plug-in
Sword finger offer 04 Search in two-dimensional array
每日一题-无重复字符的最长子串
【Jailhouse 文章】Jailhouse Hypervisor
shared_ Repeated release heap object of PTR hidden danger
CF1634 F. Fibonacci Additions
每日一题-搜索二维矩阵ps二维数组的查找
F - Two Exam(AtCoder Beginner Contest 238)
ssh免密登录设置及使用脚本进行ssh登录并执行指令
Sword finger offer 35 Replication of complex linked list
Solution to game 10 of the personal field
Individual game 12
Sword finger offer 53 - I. find the number I in the sorted array
Cluster script of data warehouse project
2017 USP Try-outs C. Coprimes
智慧工地“水电能耗在线监测系统”
剑指 Offer 35.复杂链表的复制