Zheaoli / do-something-right

MIT License
37 stars 3 forks source link

2022-10-05 #381

Open Zheaoli opened 1 year ago

Zheaoli commented 1 year ago

2022-10-05

Dapeus commented 1 year ago

image

dreamhunter2333 commented 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 插件