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].

思路

代码

最新文章

  1. Beta阶段项目展示
  2. 关于composer安装插件时候提示找不到fxp插件时候的解决办法
  3. AI(Adobe Illustrator)简单入门——小熊
  4. 引用POPUI来实现弹窗效果,且弹窗中的内容可以点击事件
  5. [html]html常用代码
  6. 总结iframe高度自适应,自适应子页面高度
  7. js让菜单栏一直悬浮在顶部,经典代码
  8. oracle与SqlServer连接串服务器地址
  9. MyBatis CRUD Java POJO操作
  10. 使用SoapUI工具做get请求和post请求接口测试
  11. linux grep 从入门到精通
  12. sublime text 3 无法安装Package Control插件解决办法
  13. HTML设为首页/加入收藏代码
  14. bzoj 2726 任务安排(3)/loj 10184-10186 斜率优化
  15. PMS及APP安装过程
  16. linux系统关闭指定服务的方式
  17. 【对比分析四】position的absolute与fixed共同点与不同点
  18. OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000083e80000, 1366294528, 0) failed;
  19. Day 49 CSS样式.
  20. 计算机网络【1】—— OSI七层协议和TCP/IP四层协议

热门文章

  1. Immunity Debugger学习笔记
  2. [转]Tornado get/post请求异步处理框架分析
  3. spark sql 的性能调优
  4. AJAX相关总结
  5. ORM Nhibernate框架在项目中的配置
  6. LaunchFaster 启动器工具 - 类似 Rolan 和音速启动的图标式快捷启动软件
  7. linux 之 压缩 / 解压
  8. vmware桥接模式无法上网
  9. spring boot 自定义异常
  10. restfull 风格 参考 https://blog.csdn.net/jaryle/article/details/52141097