zoukankan      html  css  js  c++  java
  • [Swift]LeetCode1282. 用户分组 | Group the People Given the Group Size They Belong To

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(let_us_code)
    ➤博主域名:https://www.zengqiang.org
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/12151562.html
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    There are n people whose IDs go from 0 to n - 1 and each person belongs exactly to one group. Given the array groupSizes of length n telling the group size each person belongs to, return the groups there are and the people's IDs each group includes.

    You can return any solution in any order and the same applies for IDs. Also, it is guaranteed that there exists at least one solution. 

    Example 1:

    Input: groupSizes = [3,3,3,3,3,1,3]
    Output: [[5],[0,1,2],[3,4,6]]
    Explanation:
    Other possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].
    Example 2:

    Input: groupSizes = [2,1,3,3,3,2]
    Output: [[1],[0,5],[2,3,4]]
     

    Constraints:

    groupSizes.length == n
    1 <= n <= 500
    1 <= groupSizes[i] <= n


    有 n 位用户参加活动,他们的 ID 从 0 到 n - 1,每位用户都 恰好 属于某一用户组。给你一个长度为 n 的数组 groupSizes,其中包含每位用户所处的用户组的大小,请你返回用户分组情况(存在的用户组以及每个组中用户的 ID)。

    你可以任何顺序返回解决方案,ID 的顺序也不受限制。此外,题目给出的数据保证至少存在一种解决方案。

    示例 1:

    输入:groupSizes = [3,3,3,3,3,1,3]
    输出:[[5],[0,1,2],[3,4,6]]
    解释:
    其他可能的解决方案有 [[2,1,6],[5],[0,4,3]] 和 [[5],[0,6,2],[4,3,1]]。
    示例 2:

    输入:groupSizes = [2,1,3,3,3,2]
    输出:[[1],[0,5],[2,3,4]]
     

    提示:

    groupSizes.length == n
    1 <= n <= 500
    1 <= groupSizes[i] <= n

  • 相关阅读:
    常用的dos命令
    定时器
    自动化工具下载地址
    Eclipse自动提示
    An error occurred: No action handlers found
    生产消费的经典案例
    SpringBoot 优雅的参数效验
    40 个 SpringBoot 常用注解
    极简入门,Shiro的认证与授权流程解析
    Java多线程批量处理、线程池的使用
  • 原文地址:https://www.cnblogs.com/strengthen/p/12151562.html
Copyright © 2011-2022 走看看