leetcode 811. Subdomain Visit Count python

class Solution(object):
    def subdomainVisits(self, cpdomains):
        """
        :type cpdomains: List[str]
        :rtype: List[str]
        """
        ant = collections.Counter()
        for domains in cpdomains:
            count,domain = domains.split()
            count = int(count)
            frags = domain.split('.')
            for i in range(len(frags)):
                ant['.'.join(frags[i:])] += count
        return['{} {}'.format(x,y) for y,x in ant.items()]

像“discuss.leetcode.com”这样的网站域包含各种子域。 在顶层,我们有“com”,在下一个层次,我们有“leetcode.com”,最低的层次是“discuss.leetcode.com”。 当我们访问像“discuss.leetcode.com”这样的域名时,我们也会隐式访问父域“leetcode.com”和“com”。

给定输入,计算每个子域的访问次数。

. join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。

[ i: ] 表示 包括 i 之后所有的index 

In [1]: '{0},{1}'.format('kzc',18) 
Out[1]: 'kzc,18' 
In [2]: '{},{}'.format('kzc',18) 
Out[2]: 'kzc,18' 
In [3]: '{1},{0},{1}'.format('kzc',18) 
Out[3]: '18,kzc,18'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值