力扣第991题 坏了的计算器

力扣第991题 坏了的计算器

class Solution {
    public:
    int brokenCalc(int X, int Y) {
        int res = 0;
        while (Y > X)
        {
            res++;
            if ((Y & 1))
            {
                Y++;
            }
            else
            {
                Y >>= 1;
            }
        }
        return res + X - Y;
    }
};

posted on 2020-03-08 20:52  woodjay  阅读(151)  评论(0编辑  收藏  举报

导航