1 Star 0 Fork 18

busfly/力扣题库(完整版)

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
broken-calculator.html 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
小墨 提交于 2022-05-02 23:40 +08:00 . 更新国外版力扣题目描述变更
<p>There is a broken calculator that has the integer <code>startValue</code> on its display initially. In one operation, you can:</p>
<ul>
<li>multiply the number on display by <code>2</code>, or</li>
<li>subtract <code>1</code> from the number on display.</li>
</ul>
<p>Given two integers <code>startValue</code> and <code>target</code>, return <em>the minimum number of operations needed to display </em><code>target</code><em> on the calculator</em>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> startValue = 2, target = 3
<strong>Output:</strong> 2
<strong>Explanation:</strong> Use double operation and then decrement operation {2 -&gt; 4 -&gt; 3}.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> startValue = 5, target = 8
<strong>Output:</strong> 2
<strong>Explanation:</strong> Use decrement and then double {5 -&gt; 4 -&gt; 8}.
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> startValue = 3, target = 10
<strong>Output:</strong> 3
<strong>Explanation:</strong> Use double, decrement and double {3 -&gt; 6 -&gt; 5 -&gt; 10}.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= startValue, target &lt;= 10<sup>9</sup></code></li>
</ul>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/busfly/leetcode-problemset.git
git@gitee.com:busfly/leetcode-problemset.git
busfly
leetcode-problemset
力扣题库(完整版)
master

搜索帮助