본문 바로가기
개발 노트/LeetCode 풀이

[JS] 1342. Number of Steps to Reduce a Number to Zero

by tokkiC 2022. 11. 18.

리트코드 easy 난이도는 쉬운 문제가 많다

백준 브론즈 1에서 실버 5 정도도 꽤 있는듯하다

https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/

 

Number of Steps to Reduce a Number to Zero - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

/**
 * @param {number} num
 * @return {number}
 */
var numberOfSteps = function (num) {
  let step = 0;
  while (num) {
    step++;
    if (num % 2 === 0) {
      num /= 2;
    } else {
      num--;
    }
  }
  return step;
};

 

'개발 노트 > LeetCode 풀이' 카테고리의 다른 글

[JS] 1. Two Sum  (0) 2022.11.22
[JS] 383. Ransom Note  (0) 2022.11.18
[JS] 412. Fizz Buzz  (0) 2022.11.16
[JS] 1672. Richest Customer Wealth  (0) 2022.11.16
[JS] 1480. Running Sum of 1d Array  (0) 2022.11.15

댓글