forked from yuzhangcmu/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebFind.java
executable file
·39 lines (30 loc) · 887 Bytes
/
WebFind.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package Algorithms;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
public class WebFind {
public class UrlGraph {
String val;
ArrayList<UrlGraph> childrens;
public UrlGraph(String val) {
super();
this.val = val;
this.childrens = new ArrayList<UrlGraph>();
}
}
public UrlGraph webClown(String url, HashMap<String, UrlGraph> map) {
if (map.containsKey(url)) {
return map.get(url);
}
UrlGraph node = new UrlGraph(url);
ArrayList<String> list = getUrls(url);
for (String sub: list) {
node.childrens.add(webClown(sub, map));
}
map.put(url, node);
return node;
}
public ArrayList<String> getUrls(String url) {
//return
}
}