-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSubdomain Visit Count.py
31 lines (29 loc) · 1.01 KB
/
Subdomain Visit Count.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#Subdomain Visit Count
#https://leetcode.com/problems/subdomain-visit-count/
class Solution(object):
def __init__(self):
self.ht = {}
def countSubDomain(self, visitCount, domain):
domainSplit = domain.split(".")
for i in range(len(domainSplit)):
key = ".".join(domainSplit[i:])
if not(key in self.ht):
self.ht[key] = visitCount
else:
self.ht[key] = self.ht[key] + visitCount
def subdomainVisits(self, cpdomains):
for cpdomain in cpdomains:
domainSplit = cpdomain.split(" ")
self.countSubDomain(int(domainSplit[0]), domainSplit[1])
output = []
for key in self.ht:
string = str(self.ht[key])+" "+key
output.append(string)
print output
"""
:type cpdomains: List[str]
:rtype: List[str]
"""
#Main
obj = Solution()
obj.subdomainVisits(["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"])