文件名称:leetcode伪代码-number-of-steps-to-reduce-to-zero:减少到零的步数
文件大小:3KB
文件格式:ZIP
更新时间:2024-07-20 13:43:58
系统开源
leetcode伪代码number of steps to reduce a number to zero 题目解读: 题目来源: 原文: Given a non-negative integer num, return the number of steps to reduce it to zero. If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it. 解读: 给定一个正整数num 依据以下的法则num递减到0 1 如果num 是偶数则让num = num/2 2 如果num 不是偶数则让num = num -1 写一个function 计算出所需要的步骤数目 初步解法: 初步观察: 首先是需要把每个步骤利用一个counter记录下来 每做一步把counter加一 初步设计: Given an integer num, num > 0 step 1: set a integer count = 0 step 2: check if n
【文件预览】:
number-of-steps-to-reduce-to-zero-master
----.gitignore(269B)
----README.md(2KB)
----numberOfSteps_test.go(531B)
----numberOfSteps.go(177B)