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)/子数组最大平均数 I [maximum-average-subarray-i].html
2022-03-29 12:43:11 +08:00

33 lines
945 B
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个由 <code>n</code> 个元素组成的整数数组 <code>nums</code> 和一个整数 <code>k</code></p>
<p>请你找出平均数最大且 <strong>长度为 <code>k</code></strong> 的连续子数组,并输出该最大平均数。</p>
<p>任何误差小于 <code>10<sup>-5</sup></code> 的答案都将被视为正确答案。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,12,-5,-6,50,3], k = 4
<strong>输出:</strong>12.75
<strong>解释:</strong>最大平均数 (12-5-6+50)/4 = 51/4 = 12.75
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [5], k = 1
<strong>输出:</strong>5.00000
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 &lt;= k &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>