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

 

相关文章:

  • 2021-11-22
  • 2021-08-02
  • 2021-10-07
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-30
  • 2022-03-03
  • 2021-07-05
  • 2022-12-23
  • 2021-11-11
  • 2021-12-12
  • 2021-08-27
相关资源
相似解决方案