标签:while bsp obj find pen object class sel visit
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
标签:while bsp obj find pen object class sel visit
原文地址:https://www.cnblogs.com/zywscq/p/10569040.html