#811
Subdomain Visit Count
pupil · 535 · lc medium +28 · verified · 77.2% accepted · 1,597 likes · top 88%
Description
A website domain such as "discuss.leetcode.com" is composed of nested subdomains. Visiting "discuss.leetcode.com" implicitly counts as a visit to "leetcode.com" and "com" as well.
A count-paired domain is a string in the format "rep d1.d2.d3" or "rep d1.d2", where rep is the visit count for that domain.
- For example, "9001 discuss.leetcode.com" indicates that discuss.leetcode.com was visited 9001 times.
Given an array of count-paired domains cpdomains, return an array of count-paired domains tallying the total visits for each subdomain across all entries. The result may be in any order.
Example 1:
Input: cpdomains = ["9001 discuss.leetcode.com"]
Output: ["9001 leetcode.com","9001 discuss.leetcode.com","9001 com"]
Explanation: We only have one website domain: "discuss.leetcode.com".
As discussed above, the subdomain "leetcode.com" and "com" will also be visited. So they will all be visited 9001 times.
Example 2:
Input: cpdomains = ["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"]
Output: ["901 mail.com","50 yahoo.com","900 google.mail.com","5 wiki.org","5 org","1 intel.mail.com","951 com"]
Explanation: We will visit "google.mail.com" 900 times, "yahoo.com" 50 times, "intel.mail.com" once and "wiki.org" 5 times.
For the subdomains, we will visit "mail.com" 900 + 1 = 901 times, "com" 900 + 50 + 1 = 951 times, and "org" 5 times.
Code
1
2
3