Leetcode 811. Subdomain Visit Count
阿新 • • 發佈:2019-03-21
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