1. 程式人生 > >Leetcode 811. Subdomain Visit Count

Leetcode 811. Subdomain Visit Count

color turn def bsp ans div return self object

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