Given a list accounts, each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.

Now, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some email that is common to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.

After merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails in sorted order. The accounts themselves can be returned in any order.

Example 1:

Input:
accounts = [["John", "johnsmith@mail.com", "john00@mail.com"], ["John", "johnnybravo@mail.com"], ["John", "johnsmith@mail.com", "john_newyork@mail.com"], ["Mary", "mary@mail.com"]]
Output: [["John", 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com'], ["John", "johnnybravo@mail.com"], ["Mary", "mary@mail.com"]]
Explanation:
The first and third John's are the same person as they have the common email "johnsmith@mail.com".
The second John and Mary are different people as none of their email addresses are used by other accounts.
We could return these lists in any order, for example the answer [['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com'],
['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com']] would still be accepted.

Note:

  • The length of accounts will be in the range [1, 1000].
  • The length of accounts[i] will be in the range [1, 10].
  • The length of accounts[i][j] will be in the range [1, 30].

思路

代码

[leetcode]721. Accounts Merge账户合并的更多相关文章

  1. [LeetCode] 721. Accounts Merge 账户合并

    Given a list accounts, each element accounts[i] is a list of strings, where the first element accoun ...

  2. 【leetcode】721. Accounts Merge(账户合并)

    Given a list of accounts where each element accounts[i] is a list of strings, where the first elemen ...

  3. [LeetCode] Accounts Merge 账户合并

    Given a list accounts, each element accounts[i] is a list of strings, where the first element accoun ...

  4. LeetCode 721. Accounts Merge

    原题链接在这里:https://leetcode.com/problems/accounts-merge/ 题目: Given a list accounts, each element accoun ...

  5. 【LeetCode】721. Accounts Merge 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/accounts ...

  6. 721. Accounts Merge合并电子邮件账户

    [抄题]: Given a list accounts, each element accounts[i] is a list of strings, where the first element  ...

  7. Leetcode(712)-账户合并

    给定一个列表 accounts,每个元素 accounts[i] 是一个字符串列表,其中第一个元素 accounts[i][0] 是 名称 (name),其余元素是 emails 表示该帐户的邮箱地址 ...

  8. [LeetCode] 721. Accounts Merge_Medium tag: DFS recursive

    Given a list accounts, each element accounts[i] is a list of strings, where the first element accoun ...

  9. 721. Accounts Merge

    https://leetcode.com/problems/accounts-merge/description/ class UnionFound { public: unordered_map&l ...

随机推荐

  1. centos7 设置系统时间与网络同步

    1.安装ntpdate工具 yum -y install ntp ntpdate 2.设置系统时间与网络时间同步 ntpdate cn.pool.ntp.org 3.将系统时间写入硬件时间 hwclo ...

  2. 解决IE下select标签innerHTML插入option的BUG(兼容

    在ie下面使用innerHTML来插入option选项的话,ie会去掉前面的<option>,并拆分成多个节点,这样会造成select的出错   前言: 这是一个老bug了,现在提供一个完 ...

  3. Oracle 某字段值相同的取前几条数据

    rank() over(partition)的使用(转载)   有的时候会遇到这样的问题,我们需要查询一张表,而且要按照业务排序,比如我需要如下的结果: 地区   日期    费用  产品编号   用 ...

  4. unity3d中gameObject捕获鼠标点击

    gameObject需加上Colider 一.在update中(推荐) void Update () { //左键 )) disFlag = true; //右键 )) disFlag = true; ...

  5. while_else

    使用while循环输出100-50,从大到小,到50的时候,再从0到50输出,然后结束count =

  6. 小朋友学Python(4)

    Mac下安装Python 3 Mac系统会自带Python 2.7.x.安装Python 3时,不要卸载Python 2.7.x,因为有Mac系统有一些库会依赖于Python 2.7.x. 安装步骤: ...

  7. Bogart gSub.vb

    '--------------Job No 0900408 -------------- '--DIM PART ONE ONLINE Update Order Qty '''主要新加過程名 Refr ...

  8. diffutils's diff

    比较文件的差异 diff,用来查看两个文件的差异之处,或者两个目录之中的对应文件.倘若比较的不是文本文件,而是二进制文件,只会报告两者不同.输出文本文件的异同时,可以按照多个格式输出,根据使用的选项决 ...

  9. python2-python3字符串

    https://www.cnblogs.com/yangmingxianshen/p/7990102.html

  10. docker容器中搭建kafka集群环境

    Kafka集群管理.状态保存是通过zookeeper实现,所以先要搭建zookeeper集群 zookeeper集群搭建 一.软件环境: zookeeper集群需要超过半数的的node存活才能对外服务 ...