991. Broken Calculator Medium
1/**
2 * [991] Broken Calculator
3 *
4 * There is a broken calculator that has the integer startValue on its display initially. In one operation, you can:
5 *
6 * multiply the number on display by 2, or
7 * subtract 1 from the number on display.
8 *
9 * Given two integers startValue and target, return the minimum number of operations needed to display target on the calculator.
10 *
11 * Example 1:
12 *
13 * Input: startValue = 2, target = 3
14 * Output: 2
15 * Explanation: Use double operation and then decrement operation {2 -> 4 -> 3}.
16 *
17 * Example 2:
18 *
19 * Input: startValue = 5, target = 8
20 * Output: 2
21 * Explanation: Use decrement and then double {5 -> 4 -> 8}.
22 *
23 * Example 3:
24 *
25 * Input: startValue = 3, target = 10
26 * Output: 3
27 * Explanation: Use double, decrement and double {3 -> 6 -> 5 -> 10}.
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= startValue, target <= 10^9
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/broken-calculator/
38// discuss: https://leetcode.com/problems/broken-calculator/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn broken_calc(start_value: i32, target: i32) -> i32 {
44 0
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_991() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.