Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * // This is the HtmlParser's API interface.
- * // You should not implement it, or speculate about its implementation
- * class HtmlParser {
- * public:
- * vector<string> getUrls(string url);
- * };
- */
- class Solution {
- public:
- vector<string> crawl(string startUrl, HtmlParser htmlParser) {
- vector<string> ans;
- unordered_set<string> m;
- string hostname = startUrl.substr(0, startUrl.find('/', 7));
- queue<string> q;
- q.push(startUrl);
- m.insert(startUrl);
- ans.push_back(startUrl);
- while(!q.empty()){
- string url = q.front(); q.pop();
- for(auto child: htmlParser.getUrls(url)){
- if(child.find(hostname) == string::npos || m.count(child))
- continue;
- m.insert(child);
- q.push(child);
- ans.push_back(child);
- }
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment