【Leetcode_easy】811. Subdomain Visit Count
problem
solution:
class Solution {
public:
vector<string> subdomainVisits(vector<string>& cpdomains) {
vector<string> res;
unordered_map<string, int> subdomain;
int spaceIdx = ;
for(auto cpdomain:cpdomains)
{
spaceIdx = cpdomain.find(" ");//errrrr...
int cnt = stoi(cpdomain.substr(, spaceIdx));
string tmp = cpdomain.substr(spaceIdx+);
for(int i=; i<tmp.size(); ++i)
{
if(tmp[i]=='.') subdomain[tmp.substr(i+)] += cnt;//errr.
}
subdomain[tmp] += cnt;//err..
}
for(auto sub:subdomain)
{
res.push_back(to_string(sub.second) + " " + sub.first);//errr...
}
return res;
}
};
参考
1. Leetcode_easy_811. Subdomain Visit Count;
2. Grandyang;
完
【Leetcode_easy】811. Subdomain Visit Count的更多相关文章
- 【LeetCode】811. Subdomain Visit Count 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典统计次数 日期 题目地址:https://lee ...
- 811. Subdomain Visit Count - LeetCode
Question 811. Subdomain Visit Count Example 1: Input: ["9001 discuss.leetcode.com"] Output ...
- LeetCode 811 Subdomain Visit Count 解题报告
题目要求 A website domain like "discuss.leetcode.com" consists of various subdomains. At the t ...
- [LeetCode&Python] Problem 811. Subdomain Visit Count
A website domain like "discuss.leetcode.com" consists of various subdomains. At the top le ...
- LeetCode 811. Subdomain Visit Count (子域名访问计数)
题目标签:HashMap 题目给了我们一组域名,让我们把每一个域名,包括它的子域名,计数. 遍历每一个域名,取得它的计数,然后把它的所有子域名和它自己,存入hashmap,域名作为key,计数作为va ...
- 811. Subdomain Visit Count (5月23日)
解答 class Solution { public: vector<string> subdomainVisits(vector<string>& cpdomains ...
- 811. Subdomain Visit Count
这题主要难在构建关联容器,方法很多,但是核心都是把原字符串一截一截减下来处理,先把前面用空格隔开的次数转化为整数,然后处理后面的多层子域. 方法一,查找标志字符,用标志字符把字符串分成几段 stati ...
- LeetCode算法题-Subdomain Visit Count(Java实现)
这是悦乐书的第320次更新,第341篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第189题(顺位题号是811).像"discuss.leetcode.com& ...
- 【mysql】mysql统计查询count的效率优化问题
mysql统计查询count的效率优化问题 涉及到一个问题 就是 mysql的二级索引的问题,聚簇索引和非聚簇索引 引申地址:https://www.cnblogs.com/sxdcgaq8080/p ...
随机推荐
- BZOJ 3698: XWW的难题(有源汇上下界最大流)
题面 XWW是个影响力很大的人,他有很多的追随者.这些追随者都想要加入XWW教成为XWW的教徒.但是这并不容易,需要通过XWW的考核. XWW给你出了这么一个难题:XWW给你一个N*N的正实数矩阵A, ...
- python xlwt 设置单元格样式
使用xlwt中的Alignment来设置单元格的对齐方式,其中horz代表水平对齐方式,vert代表垂直对齐方式. VERT_TOP = 0x00 上端对齐 VERT_CENTER = 0x01 居中 ...
- 012_Python3 斐波纳契数列 + end 关键字
1.个斐波纳契数列. #!/usr/bin/python3 # Fibonacci series: 斐波纳契数列 # 两个元素的总和确定了下一个数 a, b = 0, 1 while b < ...
- 后缀数组 1031: [JSOI2007]字符加密Cipher
/*1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4926 Solved: 2020[Submit ...
- 爬虫(十八):scrapy分布式部署
scrapy部署神器-scrapyd -->GitHub地址 -->官方文档 一:安装scrapyd 安装:pip3 install scrapyd 这里我在另外一台ubuntu lin ...
- linux系列(十二):more命令
1.命令格式: more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] [file] 2.命令功能: more命令和cat的功能一样都是查看文件里的内容,但 ...
- Python基础之只接收关键字参数的函数
当我们希望函数的某些参数强制使用关键字参数时,可以将强制关键字参数放到某个*后面就能得到这种效果.比如: def recv(maxsize, *, block): """ ...
- Ubuntu 14.04 源
清华源https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/ ubuntu 14.04 官方源 # deb cdrom:[Ubuntu 14.04.4 LT ...
- Spring Cloud Gateway(七):路由谓词工厂WeightRoutePredicateFactory
本文基于 spring cloud gateway 2.0.1 接上文 5.基于路由权重(weigth)的谓词工厂 Spring Cloud Gateway 提供了基于路由权重的断言工厂,配置时指定分 ...
- Ansible 模式
一.Ansible 命令 1.Ansible 命令执行的方式有两种:Ad-Hoc.Ansible-playbooks,这两种方式没有本质的区别,Ad-Hoc用于临时执行命令:Ansible-playb ...