Dashboard Temp Share Shortlinks Frames API

HTMLify

LeetCode - Minimum Moves to Reach Target Score - C
Views: 4 | Author: abh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
// @leet start
int minMoves(int target, int maxDoubles) {
    int steps = 0;
    while (target > 1 && maxDoubles) {
        if (target % 2 == 0) {
            target /= 2;
            maxDoubles--;
        } else {
            target -= 1;
        }
        steps++;
    }
    steps += target - 1;
    return steps;
}
// @leet end