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)/盒子中小球的最大数量 [maximum-number-of-balls-in-a-box].html
2022-03-29 12:43:11 +08:00

48 lines
2.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>lowLimit</code> 开始,到 <code>highLimit</code> 结束(包括 <code>lowLimit</code> 和 <code>highLimit</code> ,即 <code>n == highLimit - lowLimit + 1</code>)。另有无限数量的盒子,编号从 <code>1</code><code>infinity</code></p>
<p>你的工作是将每个小球放入盒子中,其中盒子的编号应当等于小球编号上每位数字的和。例如,编号 <code>321</code> 的小球应当放入编号 <code>3 + 2 + 1 = 6</code> 的盒子,而编号 <code>10</code> 的小球应当放入编号 <code>1 + 0 = 1</code> 的盒子。</p>
<p>给你两个整数 <code>lowLimit</code><code>highLimit</code> ,返回放有最多小球的盒子中的小球数量<em></em>如果有多个盒子都满足放有最多小球,只需返回其中任一盒子的小球数量。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>lowLimit = 1, highLimit = 10
<strong>输出:</strong>2
<strong>解释:</strong>
盒子编号1 2 3 4 5 6 7 8 9 10 11 ...
小球数量2 1 1 1 1 1 1 1 1 0 0 ...
编号 1 的盒子放有最多小球,小球数量为 2 。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>lowLimit = 5, highLimit = 15
<strong>输出:</strong>2
<strong>解释:</strong>
盒子编号1 2 3 4 5 6 7 8 9 10 11 ...
小球数量1 1 1 1 2 2 1 1 1 0 0 ...
编号 5 和 6 的盒子放有最多小球,每个盒子中的小球数量都是 2 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>lowLimit = 19, highLimit = 28
<strong>输出:</strong>2
<strong>解释:</strong>
盒子编号1 2 3 4 5 6 7 8 9 10 11 12 ...
小球数量0 1 1 1 1 1 1 1 1 2 0 0 ...
编号 10 的盒子放有最多小球,小球数量为 2 。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= lowLimit <= highLimit <= 10<sup>5</sup></code></li>
</ul>