1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 19:18:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/大样本统计 [statistics-from-a-large-sample].html

55 lines
3.5 KiB
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<p>我们对&nbsp;<code>0</code>&nbsp;&nbsp;<code>255</code>&nbsp;之间的整数进行采样,并将结果存储在数组&nbsp;<code>count</code>&nbsp;中:<code>count[k]</code>&nbsp;就是整数&nbsp;<code>k</code> 在样本中出现的次数。</p>
<p>计算以下统计数据:</p>
<ul>
<li><code>minimum</code>&nbsp;:样本中的最小元素。</li>
<li><code>maximum</code>&nbsp;:样品中的最大元素。</li>
<li><code>mean</code>&nbsp;:样本的平均值,计算为所有元素的总和除以元素总数。</li>
<li><code>median</code>&nbsp;
<ul>
<li>如果样本的元素个数是奇数,那么一旦样本排序后,中位数 <code>median</code> 就是中间的元素。</li>
<li>如果样本中有偶数个元素,那么中位数<code>median</code> 就是样本排序后中间两个元素的平均值。</li>
</ul>
</li>
<li><code>mode</code>&nbsp;:样本中出现次数最多的数字。保众数是 <strong>唯一</strong> 的。</li>
</ul>
<p>以浮点数数组的形式返回样本的统计信息<em>&nbsp;</em><code>[minimum, maximum, mean, median, mode]</code>&nbsp;。与真实答案误差在<em>&nbsp;</em><code>10<sup>-5</sup></code><em>&nbsp;</em>内的答案都可以通过。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
<strong>输出:</strong>[1.00000,3.00000,2.37500,2.50000,3.00000]
<strong>解释:</strong>用count表示的样本为[1,2,2,2,3,3,3,3,3]。
最小值和最大值分别为1和3。
均值是(1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375。
因为样本的大小是偶数所以中位数是中间两个元素2和3的平均值也就是2.5。
众数为3因为它在样本中出现的次数最多。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
<strong>输出:</strong>[1.00000,4.00000,2.18182,2.00000,1.00000]
<strong>解释:</strong>用count表示的样本为[1,1,1,1,2,2,3,3,3,4,4]。
最小值为1最大值为4。
平均数是(1+1+1+1+2+2+2+3+3+4+4)/ 11 = 24 / 11 = 2.18181818…(为了显示输出显示了整数2.18182)。
因为样本的大小是奇数所以中值是中间元素2。
众数为1因为它在样本中出现的次数最多。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>count.length == 256</code></li>
<li><code>0 &lt;= count[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= sum(count) &lt;= 10<sup>9</sup></code></li>
<li>&nbsp;<code>count</code>&nbsp;的众数是 <strong>唯一</strong></li>
</ul>