1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/用户分组 [group-the-people-given-the-group-size-they-belong-to].html
2022-03-29 12:43:11 +08:00

39 lines
1.8 KiB
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>&nbsp;<code>n</code>&nbsp;个人被分成数量未知的组。每个人都被标记为一个从 <code>0</code><code>n - 1</code><strong>唯一ID</strong>&nbsp;</p>
<p>给定一个整数数组 <code>groupSizes</code> ,其中<meta charset="UTF-8" />&nbsp;<code>groupSizes[i]</code>&nbsp;是第 <code>i</code> 个人所在的组的大小。例如,如果&nbsp;<code>groupSizes[1] = 3</code>&nbsp;,则第 <code>1</code> 个人必须位于大小为 <code>3</code> 的组中。</p>
<p>返回一个组列表,使每个人 <code>i</code> 都在一个大小为<meta charset="UTF-8" /><em>&nbsp;<code>groupSizes[i]</code>&nbsp;</em>的组中。</p>
<p>每个人应该&nbsp;<strong>恰好只&nbsp;</strong>出现在&nbsp;<strong>一个组&nbsp;</strong>中,并且每个人必须在一个组中。如果有多个答案,返回其中&nbsp;<strong>任何&nbsp;</strong>一个。可以&nbsp;<strong>保证&nbsp;</strong>给定输入&nbsp;<strong>至少有一个&nbsp;</strong>有效的解。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>groupSizes = [3,3,3,3,3,1,3]
<strong>输出:</strong>[[5],[0,1,2],[3,4,6]]
<strong>解释:
</strong>第一组是 [5],大小为 1groupSizes[5] = 1。
第二组是 [0,1,2],大小为 3groupSizes[0] = groupSizes[1] = groupSizes[2] = 3。
第三组是 [3,4,6],大小为 3groupSizes[3] = groupSizes[4] = groupSizes[6] = 3。
其他可能的解决方案有 [[2,1,6],[5],[0,4,3]] 和 [[5],[0,6,2],[4,3,1]]。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>groupSizes = [2,1,3,3,3,2]
<strong>输出:</strong>[[1],[0,5],[2,3,4]]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>groupSizes.length == n</code></li>
<li><code>1 &lt;= n&nbsp;&lt;= 500</code></li>
<li><code>1 &lt;=&nbsp;groupSizes[i] &lt;= n</code></li>
</ul>