Practice Number of Steps to Reduce a Number in Binary Representation to One
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Medium#1404
LeetCode ProblemNumber of Steps to Reduce a Number in Binary Representation to One
Problem Statement
The string s gives a positive integer in binary. Until it becomes 1, divide the current value by 2 if even, or add 1 if odd. Return the number of operations. Every test case is guaranteed to reach 1.
Source: Number of Steps to Reduce a Number in Binary Representation to One on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
s = "1101"
Output
6
# Example 2
Input
s = "10"
Output
1
# Example 3
Input
s = "1"
Output
0
Constraints
1 <= s.length <= 500
s consists of characters '0' or '1'
s[0] == '1'
Related LeetCode Problems
Practice more problems similar to Number of Steps to Reduce a Number in Binary Representation to One.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.