1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/获取生成数组中的最大值 [get-maximum-in-generated-array].html

54 lines
1.5 KiB
HTML
Raw Normal View History

2022-03-27 20:45:09 +08:00
<p>给你一个整数 <code>n</code> 。按下述规则生成一个长度为 <code>n + 1</code> 的数组 <code>nums</code> </p>
<ul>
<li><code>nums[0] = 0</code></li>
<li><code>nums[1] = 1</code></li>
<li><code>2 <= 2 * i <= n</code> 时,<code>nums[2 * i] = nums[i]</code></li>
<li><code>2 <= 2 * i + 1 <= n</code> 时,<code>nums[2 * i + 1] = nums[i] + nums[i + 1]</code></li>
</ul>
<p>返回生成数组 <code>nums</code> 中的 <strong>最大</strong> 值。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 7
<strong>输出:</strong>3
<strong>解释:</strong>根据规则:
nums[0] = 0
nums[1] = 1
nums[(1 * 2) = 2] = nums[1] = 1
nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2
nums[(2 * 2) = 4] = nums[2] = 1
nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3
nums[(3 * 2) = 6] = nums[3] = 2
nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3
因此nums = [0,1,1,2,1,3,2,3],最大值 3
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 2
<strong>输出:</strong>1
<strong>解释:</strong>根据规则nums[0]、nums[1] 和 nums[2] 之中的最大值是 1
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>n = 3
<strong>输出:</strong>2
<strong>解释:</strong>根据规则nums[0]、nums[1]、nums[2] 和 nums[3] 之中的最大值是 2
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 <= n <= 100</code></li>
</ul>