There is a broken calculator that has the integer startValue on its display initially. In one operation, you can:


	multiply the number on display by 2, or
	subtract 1 from the number on display.


Given two integers startValue and target, return the minimum number of operations needed to display target on the calculator.

&nbsp;
Example 1:

Input: startValue = 2, target = 3
Output: 2
Explanation: Use double operation and then decrement operation {2 -&gt; 4 -&gt; 3}.


Example 2:

Input: startValue = 5, target = 8
Output: 2
Explanation: Use decrement and then double {5 -&gt; 4 -&gt; 8}.


Example 3:

Input: startValue = 3, target = 10
Output: 3
Explanation: Use double, decrement and double {3 -&gt; 6 -&gt; 5 -&gt; 10}.


&nbsp;
Constraints:


	1 &lt;= startValue, target &lt;= 109


class Solution(object):
    def brokenCalc(self, startValue, target):
        """
        :type startValue: int
        :type target: int
        :rtype: int
        """
        res = 0
        while target > startValue:
            res += 1
            if target % 2:
                target += 1
            else:
                target //= 2
        return res + startValue - target
class Solution {
    public int brokenCalc(int startValue, int target) {
        if(startValue >= target) return startValue - target;
        if(target % 2 == 0){
            return 1 + brokenCalc(startValue, target / 2);
        }
        return 1 + brokenCalc(startValue, target + 1);
    }
}
class Solution {
public:
    int brokenCalc(int startValue, int target) {
        int result=0;
        while(target>startValue)
        {
            result++;
            if(target%2==0)
                target=target/2;
            else
                target+=1;
        }
        result=result+(startValue-target);
        return result;
    }
};
/**
 * @param {number} startValue
 * @param {number} target
 * @return {number}
 */
var brokenCalc = function(startValue, target) {
    let steps = 0;

    while(target !== startValue){

        if(startValue > target){
            return steps + startValue - target;
        }
        if(target %2 === 0){
            target /= 2;
        }else {
            target += 1;

        }
        steps++;
    }
    return steps
};
Broken Calculator