1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-13 03:11:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

add leetcode problem-cn part6

This commit is contained in:
2022-03-27 20:56:26 +08:00
parent c11d601602
commit 08d1f2a596
1096 changed files with 88216 additions and 2 deletions

View File

@@ -0,0 +1,42 @@
<p>给定一个正整数&nbsp;<code>n</code> ,你可以做如下操作:</p>
<ol>
<li>如果&nbsp;<code>n</code><em>&nbsp;</em>是偶数,则用&nbsp;<code>n / 2</code>替换&nbsp;<code>n</code><em> </em></li>
<li>如果&nbsp;<code>n</code><em>&nbsp;</em>是奇数,则可以用&nbsp;<code>n + 1</code><code>n - 1</code>替换&nbsp;<code>n</code></li>
</ol>
<p>返回 <code>n</code><em>&nbsp;</em>变为 <code>1</code> 所需的 <em>最小替换次数</em></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 8
<strong>输出:</strong>3
<strong>解释:</strong>8 -&gt; 4 -&gt; 2 -&gt; 1
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 7
<strong>输出:</strong>4
<strong>解释:</strong>7 -&gt; 8 -&gt; 4 -&gt; 2 -&gt; 1
或 7 -&gt; 6 -&gt; 3 -&gt; 2 -&gt; 1
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>n = 4
<strong>输出:</strong>2
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 2<sup>31</sup> - 1</code></li>
</ul>