Class Solution

java.lang.Object
g0801_0900.s0811_subdomain_visit_count.Solution

public class Solution extends Object
811 - Subdomain Visit Count.<p>Medium</p> <p>A website domain <code>&quot;discuss.leetcode.com&quot;</code> consists of various subdomains. At the top level, we have <code>&quot;com&quot;</code>, at the next level, we have <code>&quot;leetcode.com&quot;</code> and at the lowest level, <code>&quot;discuss.leetcode.com&quot;</code>. When we visit a domain like <code>&quot;discuss.leetcode.com&quot;</code>, we will also visit the parent domains <code>&quot;leetcode.com&quot;</code> and <code>&quot;com&quot;</code> implicitly.</p> <p>A <strong>count-paired domain</strong> is a domain that has one of the two formats <code>&quot;rep d1.d2.d3&quot;</code> or <code>&quot;rep d1.d2&quot;</code> where <code>rep</code> is the number of visits to the domain and <code>d1.d2.d3</code> is the domain itself.</p> <ul> <li>For example, <code>&quot;9001 discuss.leetcode.com&quot;</code> is a <strong>count-paired domain</strong> that indicates that <code>discuss.leetcode.com</code> was visited <code>9001</code> times.</li> </ul> <p>Given an array of <strong>count-paired domains</strong> <code>cpdomains</code>, return <em>an array of the <strong>count-paired domains</strong> of each subdomain in the input</em>. You may return the answer in <strong>any order</strong>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> cpdomains = [&ldquo;9001 discuss.leetcode.com&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;9001 leetcode.com&rdquo;,&ldquo;9001 discuss.leetcode.com&rdquo;,&ldquo;9001 com&rdquo;]</p> <p><strong>Explanation:</strong> We only have one website domain: &ldquo;discuss.leetcode.com&rdquo;. As discussed above, the subdomain &ldquo;leetcode.com&rdquo; and &ldquo;com&rdquo; will also be visited. So they will all be visited 9001 times.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> cpdomains = [&ldquo;900 google.mail.com&rdquo;, &ldquo;50 yahoo.com&rdquo;, &ldquo;1 intel.mail.com&rdquo;, &ldquo;5 wiki.org&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;901 mail.com&rdquo;,&ldquo;50 yahoo.com&rdquo;,&ldquo;900 google.mail.com&rdquo;,&ldquo;5 wiki.org&rdquo;,&ldquo;5 org&rdquo;,&ldquo;1 intel.mail.com&rdquo;,&ldquo;951 com&rdquo;]</p> <p><strong>Explanation:</strong> We will visit &ldquo;google.mail.com&rdquo; 900 times, &ldquo;yahoo.com&rdquo; 50 times, &ldquo;intel.mail.com&rdquo; once and &ldquo;wiki.org&rdquo; 5 times. For the subdomains, we will visit &ldquo;mail.com&rdquo; 900 + 1 = 901 times, &ldquo;com&rdquo; 900 + 50 + 1 = 951 times, and &ldquo;org&rdquo; 5 times.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= cpdomain.length <= 100</code></li> <li><code>1 <= cpdomain[i].length <= 100</code></li> <li><code>cpdomain[i]</code> follows either the <code>&ldquo;rep<sub>i</sub> d1<sub>i</sub>.d2<sub>i</sub>.d3<sub>i</sub>&rdquo;</code> format or the <code>&ldquo;rep<sub>i</sub> d1<sub>i</sub>.d2<sub>i</sub>&rdquo;</code> format.</li> <li><code>rep<sub>i</sub></code> is an integer in the range <code>[1, 10<sup>4</sup>]</code>.</li> <li><code>d1<sub>i</sub></code>, <code>d2<sub>i</sub></code>, and <code>d3<sub>i</sub></code> consist of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details