题目标签:HashMap

  题目给了我们一组域名,让我们把每一个域名,包括它的子域名,计数。

  遍历每一个域名,取得它的计数,然后把它的所有子域名和它自己,存入hashmap,域名作为key,计数作为value。

  最后遍历keyset,把计数和域名重新组合加入result,具体请看code。

Java Solution:

Runtime: 7 ms, faster than 99.54%

Memory Usage: 36.4 MB, less than 99.04%

完成日期:03/15/2019

关键点:hashmap

class Solution
{
public List<String> subdomainVisits(String[] cpdomains)
{
// saving each domains including subdomain into map with its count
Map<String, Integer> map = new HashMap<>();
List<String> result = new ArrayList<>();
// iterate each domain
for(String str : cpdomains)
{
int index = str.indexOf(" ");
// get count frist
int count = Integer.parseInt(str.substring(0, index));
// get domain and its subdomains
String domains = str.substring(index + 1); do {
index = domains.indexOf("."); map.put(domains, map.getOrDefault(domains, 0) + count); if(index > 0) // means still having more subdomain
{
domains = domains.substring(index + 1);
} } while(index > 0); // if index == -1, it means reaching to the end
} for(String str : map.keySet())
{
result.add(map.get(str) + " " + str);
} return result;
}
}

参考资料:N/A

LeetCode 题目列表 - LeetCode Questions List

题目来源:https://leetcode.com/

LeetCode 811. Subdomain Visit Count (子域名访问计数)的更多相关文章

  1. Leetcode811.Subdomain Visit Count子域名访问计数

    一个网站域名,如"discuss.leetcode.com",包含了多个子域名.作为顶级域名,常用的有"com",下一级则有"leetcode.com ...

  2. [LeetCode] Subdomain Visit Count 子域名访问量统计

    A website domain like "discuss.leetcode.com" consists of various subdomains. At the top le ...

  3. LeetCode 811 Subdomain Visit Count 解题报告

    题目要求 A website domain like "discuss.leetcode.com" consists of various subdomains. At the t ...

  4. 811. Subdomain Visit Count - LeetCode

    Question 811. Subdomain Visit Count Example 1: Input: ["9001 discuss.leetcode.com"] Output ...

  5. Java实现 LeetCode 811 子域名访问计数 (暴力)

    811. 子域名访问计数 一个网站域名,如"discuss.leetcode.com",包含了多个子域名.作为顶级域名,常用的有"com",下一级则有" ...

  6. 【Leetcode_easy】811. Subdomain Visit Count

    problem 811. Subdomain Visit Count solution: class Solution { public: vector<string> subdomain ...

  7. [Swift]LeetCode811. 子域名访问计数 | Subdomain Visit Count

    A website domain like "discuss.leetcode.com" consists of various subdomains. At the top le ...

  8. 【LeetCode】811. Subdomain Visit Count 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典统计次数 日期 题目地址:https://lee ...

  9. [LeetCode&Python] Problem 811. Subdomain Visit Count

    A website domain like "discuss.leetcode.com" consists of various subdomains. At the top le ...

随机推荐

  1. NX自动出图

    小秀一下战果: 1. 自动添加图框2. 自动添加投影视图3. 自动标注外形尺寸4. 根据工艺要求,自动添加公差5. 自动孔表6. 批量打印 欢迎大家积极吐槽哈 [视频演示] http://v.youk ...

  2. MFC_1.3 控件子类化 消息反射

    控件子类化 如果想要在默认的控件类中添加一些功能,就需要子类化一个控件类 在类内可以响应控件所有的消息,并且可以添加自己的函数和数据 通过类向导子类化控件的步骤 打开类向导,创建一个 MFC 类,不要 ...

  3. Linux的网卡由eth0变成了eth1或eth2,如何修复??

    背景:做linux下分布式测试的时候,重新安装了两个linux虚拟机,结果分布式脚本没有做好,分布式也没有做成. 今天想练练linux命令,打开vmware,启动linux1 虚拟机,使用ifconf ...

  4. GEO/SRA数据库

    GEO数据库 GEO数据库隶属于NCBI,是最大最全面的基因表达数据库,主要是芯片和转录组测序数据.除储存数据外,也提供一些数据挖掘工具,因此利用好这个数据库,没有实验,没有自己的数据也能发好文章! ...

  5. vue过渡 & 动画---进入/离开 & 列表过渡

    (1)概述 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animat ...

  6. 01网页<head></head>常用标记及属性

    网页<head></head>常用标记及属性 <!DOCTYPE html> <html> <head> <!--网页标题--> ...

  7. JSONP 应用

    受限于浏览器的同源安全策略, js 无法发起跨域的请求. 但是 HTML 中的 <script> 标签却可以引入跨域的文件使用. 而 JSONP 就是利用 <script> 的 ...

  8. scala学习(2)---option空值处理

    https://blog.csdn.net/shadowsama/article/details/78148919 https://www.cnblogs.com/mustone/p/5648914. ...

  9. QT使用插件QAxWidget来展示web页面

    要求:用qt版开发一个桌面程序,该程序有一个界面,用来显示一个采用silverlight开发的web页面. 分析:在qt中实现web显示,根据qt的版本和对应编译器的版本,有如下选择: (1)5.6以 ...

  10. ORACLE 查看当前用户信息(用户,表视图,索引,表空间,同义词,存储过程,约束条件)

    1.用户 查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select ...