Subdomain Visit Count
Key formation hash table
Last updated
Key formation hash table
Last updated
class Solution:
def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
d = {}
for string in cpdomains:
n, domains = string.split()
n, domains = int(n), domains.split(".")
print(domains)
for i in range(len(domains)):
s = ".".join(domains[i:])
if s not in d:
d[s] = n
else:
d[s]+=n
res = []
for key, value in d.items():
res.append(str(value) + " " + key)
return(res)