mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
43 lines
1.3 KiB
HTML
43 lines
1.3 KiB
HTML
<p>在显示着数字 <code>startValue</code> 的坏计算器上,我们可以执行以下两种操作:</p>
|
||
|
||
<ul>
|
||
<li><strong>双倍(Double):</strong>将显示屏上的数字乘 2;</li>
|
||
<li><strong>递减(Decrement):</strong>将显示屏上的数字减 <code>1</code> 。</li>
|
||
</ul>
|
||
|
||
<p>给定两个整数 <code>startValue</code> 和 <code>target</code> 。返回显示数字 <code>target</code> 所需的最小操作数。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>startValue = 2, target = 3
|
||
<strong>输出:</strong>2
|
||
<strong>解释:</strong>先进行双倍运算,然后再进行递减运算 {2 -> 4 -> 3}.
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>startValue = 5, target = 8
|
||
<strong>输出:</strong>2
|
||
<strong>解释:</strong>先递减,再双倍 {5 -> 4 -> 8}.
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>startValue = 3, target = 10
|
||
<strong>输出:</strong>3
|
||
<strong>解释:</strong>先双倍,然后递减,再双倍 {3 -> 6 -> 5 -> 10}.
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= startValue, target <= 10<sup>9</sup></code></li>
|
||
</ul>
|