Open Zheaoli opened 1 year ago
#
# @lc app=leetcode.cn id=811 lang=python3
#
# [811] 子域名访问计数
#
from collections import defaultdict
from typing import List
# @lc code=start
class Solution:
def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
count_map = defaultdict(int)
for cpdomain in cpdomains:
count, domain = cpdomain.split(" ")
while domain:
count_map[domain] += int(count)
domain = domain.split(
".", maxsplit=1
)[1] if "." in domain else None
return [
f"{count} {domain}"
for domain, count in count_map.items()
]
# @lc code=end
微信id: 而我撑伞 来自 vscode 插件
2022-10-05