LeetCode 1342. Number of Steps to Reduce a Number to Zero (Java)
IPFS
class Solution { public int numberOfSteps(int num) { int i=0; int n=num; do{ if(n%2 == 0){ n = n/2; i++; }else if(n%2 != 0){ n = n-1; i++; } } while(n!=0); if(num==0){ i=0; } System.out.println(i); return i; } }
喜欢我的作品吗?别忘了给予支持与赞赏,让我知道在创作的路上有你陪伴,一起延续这份热忱!