[leetcode]721. Accounts Merge账户合并
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
accountswill 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账户合并的更多相关文章
- [LeetCode] 721. Accounts Merge 账户合并
Given a list accounts, each element accounts[i] is a list of strings, where the first element accoun ...
- 【leetcode】721. Accounts Merge(账户合并)
Given a list of accounts where each element accounts[i] is a list of strings, where the first elemen ...
- [LeetCode] Accounts Merge 账户合并
Given a list accounts, each element accounts[i] is a list of strings, where the first element accoun ...
- LeetCode 721. Accounts Merge
原题链接在这里:https://leetcode.com/problems/accounts-merge/ 题目: Given a list accounts, each element accoun ...
- 【LeetCode】721. Accounts Merge 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/accounts ...
- 721. Accounts Merge合并电子邮件账户
[抄题]: Given a list accounts, each element accounts[i] is a list of strings, where the first element ...
- Leetcode(712)-账户合并
给定一个列表 accounts,每个元素 accounts[i] 是一个字符串列表,其中第一个元素 accounts[i][0] 是 名称 (name),其余元素是 emails 表示该帐户的邮箱地址 ...
- [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 ...
- 721. Accounts Merge
https://leetcode.com/problems/accounts-merge/description/ class UnionFound { public: unordered_map&l ...
随机推荐
- 向Nexus仓库推送/使用各种组件
1.Nuget仓库 使用NuGetPackageExplorer打包制作自己的nupkg https://github.com/NuGetPackageExplorer/NuGetPackageExp ...
- event事件传播规则
参考原文:https://my.oschina.net/u/1454562/blog/205010 event事件传播有三个阶段:捕获阶段.目标阶段.冒泡阶段 target.addEventListe ...
- 一起KVM环境下windows7虚拟机异常死机(BSOD)的问题解决
先说一下环境: 一.硬件 8台服务器做的超融合架构,软件存储池, 每台服务器是96G内存,两颗Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz,32线程. 每台服务器是 ...
- 「SHOI2015」自动刷题机
/* 有理有据的二分答案 因为在过程中最多减到零 所以n越小显然就能刷更多的题 无解时就是无论如何也无法得到k , 这个特判一下即可 */ #include<cstdio> #includ ...
- 配置Ubuntu虚拟环境
1.ubuntu默认root用户没有激活,激活root用户,就要为root用户创建密码 $sudo passwd root 2.修改主机名 $vi /etc/hostname 3.安装ssh服 ...
- 框架之Tornado(简单介绍)
引言 回想Django的部署方式 以Django为代表的python web应用部署时采用wsgi协议与服务器对接(被服务器托管),而这类服务器通常都是基于多线程的,也就是说每一个网络请求服务器都会有 ...
- apache配置修改
1.如何设置请求等待时间 在httpd.conf里面设置: TimeOut n 其中n为整数,单位是秒. 2. 3.如何使得apache监听在特定的端口 修改httpd.con ...
- android中配置文件property的用途以及使用<转>
1.首先在源代码根目录(src下)下创建一个名为netconfig.properties的文件(也可以在其他目录下). 2.打开netconfig.properties文件,在该文件中添加下列代码. ...
- mongodb基础学习4-游标
今天来讲讲游标的操作,可以先获取一组文档,再对每一个文档进行操作. 因为mongodb底层是js引擎,所有可以像操作js一样操作mongodb,比如插入数据 游标的使用:声明游标,判断是否有下一条数据 ...
- Java操作Excel之Poi
package com.java1234.poi; import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSSF ...