leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0991.cpp (334B)


      1 class Solution {
      2   public:
      3     int brokenCalc(const int startValue, int target) const {
      4         int res = 0;
      5         while (target > startValue) {
      6             res++;
      7             if (target % 2 == 0)
      8                 target /= 2;
      9             else
     10                 target++;
     11         }
     12         return res + (startValue - target);
     13     }
     14 };