Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. class Solution(object):
  2. def subdomainVisits(self, cpdomains):
  3. """
  4. :type cpdomains: List[str]
  5. :rtype: List[str]
  6. """
  7. ht = {}
  8. sol = []
  9.  
  10. for site in cpdomains:
  11. subdoms = site.split(' ')
  12. count = int(subdoms[0])
  13. doms = subdoms[1].split('.')
  14.  
  15. for i in range(len(doms)):
  16. full = ".".join(doms[i:])
  17. if full in ht.keys():
  18. ht[full] += count
  19. else:
  20. ht[full] = count
  21.  
  22. for i in ht.items():
  23. sol.append(str(i[1]) + " " + i[0])
  24. return sol
  25.  
  26. '''
  27. Runtime: 56 ms, faster than 16.63% of Python online submissions for Subdomain Visit Count.
  28. Memory Usage: 11.8 MB, less than 47.37% of Python online submissions for Subdomain Visit Count.
  29. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement