Leetcode 811. Subdomain Visit Count

Posted 周洋的Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 811. Subdomain Visit Count相关的知识,希望对你有一定的参考价值。

class Solution(object):
    def subdomainVisits(self, cpdomains):
        """
        :type cpdomains: List[str]
        :rtype: List[str]
        """
        count = {}
        for cpdom in cpdomains:
            num, dom = cpdom.split()
            num = int(num)
            i = dom.rfind(.)
            while i != -1:
                count[dom[i + 1:]] = count.get(dom[i + 1:], 0) + num
                i=dom[0:i].rfind(.)
            count[dom] = count.get(dom, 0) + num
        ans = []
        for k, v in count.items():
            ans.append(str(v)+ +k)
        return ans

 

以上是关于Leetcode 811. Subdomain Visit Count的主要内容,如果未能解决你的问题,请参考以下文章

811. Subdomain Visit Count - LeetCode

LeetCode 811 Subdomain Visit Count 解题报告

Leetcode811 Subdomain Visit Count

Leetcode 811. Subdomain Visit Count

811. Subdomain Visit Count

811. Subdomain Visit Count