思路
代码
/*
* 2ms
*/
public String destCity(List<List<String>> paths) {
Map<String, String> map = new HashMap<>();
String start = paths.get(0).get(0);
for (List<String> path : paths) {
map.put(path.get(0), path.get(1));
}
String ans = map.get(start);
while (true) {
if (map.containsKey(ans)) {
start = ans;
ans = map.get(start);
} else {
return ans;
}
}
}
原文:https://www.cnblogs.com/yh-simon/p/12822884.html