2139. Minimum Moves to Reach Target Score Medium
1/**
2 * [2139] Minimum Moves to Reach Target Score
3 *
4 * You are playing a game with integers. You start with the integer 1 and you want to reach the integer target.
5 * In one move, you can either:
6 *
7 * Increment the current integer by one (i.e., x = x + 1).
8 * Double the current integer (i.e., x = 2 * x).
9 *
10 * You can use the increment operation any number of times, however, you can only use the double operation at most maxDoubles times.
11 * Given the two integers target and maxDoubles, return the minimum number of moves needed to reach target starting with 1.
12 *
13 * Example 1:
14 *
15 * Input: target = 5, maxDoubles = 0
16 * Output: 4
17 * Explanation: Keep incrementing by 1 until you reach target.
18 *
19 * Example 2:
20 *
21 * Input: target = 19, maxDoubles = 2
22 * Output: 7
23 * Explanation: Initially, x = 1
24 * Increment 3 times so x = 4
25 * Double once so x = 8
26 * Increment once so x = 9
27 * Double again so x = 18
28 * Increment once so x = 19
29 *
30 * Example 3:
31 *
32 * Input: target = 10, maxDoubles = 4
33 * Output: 4
34 * Explanation: Initially, x = 1
35 * Increment once so x = 2
36 * Double once so x = 4
37 * Increment once so x = 5
38 * Double again so x = 10
39 *
40 *
41 * Constraints:
42 *
43 * 1 <= target <= 10^9
44 * 0 <= maxDoubles <= 100
45 *
46 */
47pub struct Solution {}
48
49// problem: https://leetcode.com/problems/minimum-moves-to-reach-target-score/
50// discuss: https://leetcode.com/problems/minimum-moves-to-reach-target-score/discuss/?currentPage=1&orderBy=most_votes&query=
51
52// submission codes start here
53
54impl Solution {
55 pub fn min_moves(target: i32, max_doubles: i32) -> i32 {
56 0
57 }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn test_2139() {
68 }
69}
70
Back
© 2025 bowen.ge All Rights Reserved.