Easy Problems

1342. Number of Steps to Reduce a Number to Zero

Solutions

function numberOfSteps(num: number): number {
  let count = 0;
 
  while (num !== 0) {
      if (num % 2 === 0) {
          num = num / 2
      } else {
          num = num - 1;
      }
      count++;
  }
 
  return count;
};
Last Update: 12:08 - 16 April 2024
Math
Bit Manipulation

On this page