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.

&nbsp;
Example 1:

Input: s = "1101"
Output: 6
Explanation: "1101" corressponds to number 13 in their decimal representation.
Step 1) 13 is odd, add 1 and obtain 14.&nbsp;
Step 2) 14 is even, divide by 2 and obtain 7.
Step 3) 7 is odd, add 1 and obtain 8.
Step 4) 8 is even, divide by 2 and obtain 4.&nbsp; 
Step 5) 4 is even, divide by 2 and obtain 2.&nbsp;
Step 6) 2 is even, divide by 2 and obtain 1.&nbsp; 


Example 2:

Input: s = "10"
Output: 1
Explanation: "10" corressponds to number 2 in their decimal representation.
Step 1) 2 is even, divide by 2 and obtain 1.&nbsp; 


Example 3:

Input: s = "1"
Output: 0


&nbsp;
Constraints:


	1 &lt;= s.length&nbsp;&lt;= 500
	s consists of characters '0' or '1'
	s[0] == '1'


class Solution:
    def numSteps(self, s: str) -> int:
        size = len(s)
        if size == 1:
            return 0
        one_group = s.split('0')
        zero_group = s.split('1')

        
        if size - len(zero_group[-1]) == 1:
            return size - 1
        else:
            return size + len(one_group) - len(zero_group[-1])
class Solution 
{
    public int numSteps(String s)
    {
        int countSteps = 0;
        int carry = 0;
        for(int i = s.length()-1;i>=1;i--)
        {
            int rightMostBit = s.charAt(i)-'0';
            if((rightMostBit+carry) == 1)
            {
                carry=1;
                countSteps += 2;
            }
            else
            {
                countSteps++;
            }
        }
        return countSteps+carry;
    }
} 
class Solution {
public:
    int numSteps(string s) {
        int n=0;
        bool carry = false;
        int steps = 0;
        if(s == "1") return 0;
        while(s.length() > 0){
            int i = s.length()-1;
            if(carry){
                if(s[i] == '1'){
                    carry = true; s[i] = '0';
                }else{
                    s[i] = '1'; carry = false;
                }
            }
            if(s[i] == '0'){ s.pop_back(); steps++;}
            else{carry = true; s.pop_back(); steps += 2;}
            if(s == "1"){
                if(carry) steps++;
                break;
            }
        }
        return steps;
    }
};
var numSteps = function(s) {
    let res = 0;
    s = s.split("");
    while(s.length>1){
        if(s[s.length-1]==="0") s.pop();
        else plusone(s);
        res++;
    }
    return res;
};
var plusone = function(p) {
    p.unshift("0");
    let i = p.length-1;
    p[i] = 1+(+p[i]);
    while(p[i]===2){
        p[i-1] = 1+(+p[i-1]);
        i--;
        p[i+1] = "0";
    }
    if(p[0]==="0") p.shift();
    return p;
};
Number of Steps to Reduce a Number in Binary Representation to One