1404. Number of Steps to Reduce a Number in Binary Representation to One
https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one
Description
Given the binary representation of an integer as a string s
, return the number of steps to reduce it to 1
under the following rules:
If the current number is even, you have to divide it by
2
.If the current number is odd, you have to add
1
to it.
It is guaranteed that you can always reach one for all test cases.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= s.length <= 500
s
consists of characters '0' or '1's[0] == '1'
ac
Last updated