-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubdomain-visit-count.py
More file actions
31 lines (26 loc) · 960 Bytes
/
subdomain-visit-count.py
File metadata and controls
31 lines (26 loc) · 960 Bytes
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
from collections import defaultdict
class Solution:
def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
dom3 = defaultdict(int)
dom2 = defaultdict(int)
dom1 = defaultdict(int)
for cpdom in cpdomains:
cnt, dom = cpdom.split()
domc = dom.split(".")
cnt = int(cnt)
if len(domc) == 3:
x, y, z = domc
dom3[".".join(domc)] += cnt
dom2[y + "." + z] += cnt
dom1[z] += cnt
elif len(domc) == 2:
y, z = domc
dom2[y + "." + z] += cnt
dom1[z] += cnt
else:
dom1[domc[0]]
ans = []
ans.extend([str(val) + " " + dom for dom, val in dom2.items()])
ans.extend([str(val) + " " + dom for dom, val in dom3.items()])
ans.extend([str(val) + " " + dom for dom, val in dom1.items()])
return ans