题目标签: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. Python学习日记之练习代码

    # -*- coding:utf-8 -*- number = 23 test=True while test: guess=int(raw_input('输入数字')) if guess==numb ...

  2. [转] Redis在windows下安装过程

    转载自(http://www.cnblogs.com/M-LittleBird/p/5902850.html) 一.下载windows版本的Redis 去官网找了很久,发现原来在官网上可以下载的win ...

  3. iframe子页面让父页面跳转 parent.location.href

    if ($roleNum < 9) { echo "<script > parent.location.href='admin_login.php' </script ...

  4. CAD创建组(网页版)

    主要用到函数说明: _DMxDrawX::CreateGroup 创建组.如果组名已经存在,就把实体加入组中.详细说明如下: 参数 说明 BSTR pszName 组名.,如果为空,创建匿名组 IDi ...

  5. vue-quill-editor富文本焦点问题

    vue-quill-editor富文本渲染完成自动获取焦点,问题在于数据请求完成,富文本内容发生变化从而自动获取焦点 mounted() { this.$refs.myQuillEditor.quil ...

  6. 低版本ie兼容问题的解决方案

    CSS hack \9    所有的IE10及之前 *     IE7以及IE7以下版本的 _     IE6以及IE6以下版本的      !important  提升样式优先级权重 1.ie6,7 ...

  7. 剑指offer---最小的K个数

    题目:最小的K个数 要求:输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. class Solution { public: ...

  8. Flask蓝图基本使用

    Flask蓝图基本使用 Flask通过使用蓝图将视图函数模块化,使应用显得更加规整 比如我们的应用的视图函数包括用户相关和文章相关,那么我们可以通过建立两个py文件分别存储两类视图函数 user.py ...

  9. 00 大王警语--be_a_new_gentleman

    大王博客:https://www.cnblogs.com/alex3714/ # 表面层次# 1,着装特体(服饰的牌子中高端)# 2,每天洗澡# 3,适当用香水# 4,女士优先# 5,不随地吐痰.不乱 ...

  10. fillder抓取APP数据之小程序

    1.下载fillder ,fillder官网:https://www.telerik.com/fiddler 2.安装好后设置fillder: 工具—>选项,打开设置面板.选择HTTPS选项卡. ...