题目:原题链接(中等)
解法 | 时间复杂度 | 空间复杂度 | 执行用时 |
---|---|---|---|
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)