Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def subdomainVisits(self, cpdomains):
- """
- :type cpdomains: List[str]
- :rtype: List[str]
- """
- ht = {}
- sol = []
- for site in cpdomains:
- subdoms = site.split(' ')
- count = int(subdoms[0])
- doms = subdoms[1].split('.')
- for i in range(len(doms)):
- full = ".".join(doms[i:])
- if full in ht.keys():
- ht[full] += count
- else:
- ht[full] = count
- for i in ht.items():
- sol.append(str(i[1]) + " " + i[0])
- return sol
- '''
- Runtime: 56 ms, faster than 16.63% of Python online submissions for Subdomain Visit Count.
- Memory Usage: 11.8 MB, less than 47.37% of Python online submissions for Subdomain Visit Count.
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement