LeetCode题解(1236):网络爬虫(Python)

题目:原题链接(中等)

解法 时间复杂度 空间复杂度 执行用时
Ans 1 (Python) O ( N ) O(N) O(N) O ( N ) O(N) O(N) 260ms (12.50%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

class Solution:
    def crawl(self, startUrl: str, htmlParser: 'HtmlParser') -> List[str]:
        visited = {startUrl}
        queue = collections.deque([startUrl])
        host_name = 'http://' + startUrl.split('/')[2]

        while queue:
            now = queue.popleft()
            for new in htmlParser.getUrls(now):
                if new.startswith(host_name) and new not in visited:
                    queue.append(new)
                    visited.add(new)

        return list(visited)
上一篇:蓝桥杯学习记录||1236. 递增三元组


下一篇:MySQL 主从同步报1236错误