使用字典统计
class Solution:
def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
dic = {}
for i in cpdomains:
temp = i.split(' ')
n = int(temp[0])
temp = temp[1].split('.')
for j in range(len(temp)):
name = '.'.join(temp[j:])
if name in dic:
dic[name] += n
else:
dic[name] = n
return [' '.join((str(dic[i]), i)) for i in dic]