leetcode

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

2139.cpp (308B)


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