2139.cpp (308B)
1 class Solution { 2 public: 3 int minMoves(int target, int maxDoubles) const { 4 int res = 0; 5 6 while (target > 1 && maxDoubles > 0) { 7 if (target & 1) res++; 8 target >>= 1; 9 maxDoubles--; 10 res++; 11 } 12 13 return res + target - 1; 14 } 15 };