-
Notifications
You must be signed in to change notification settings - Fork 1
/
Destination City
33 lines (31 loc) · 1.07 KB
/
Destination City
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
class Solution {
public String destCity(List<List<String>> paths) {
Map<String, Integer> map = new HashMap<>();
//Map<Integer, String> map2 = new HashMap<>();
//int[][] maps = new int[paths.size()][paths.get(0).size()];
int key = 1;
List<String> a = new ArrayList<>();
for(int i = 0; i<paths.size(); i++){
for(int j = 0; j<2; j++){
if(map.containsKey(paths.get(i).get(j))){
map.replace(paths.get(i).get(j), map.get(paths.get(i).get(j))+1);
}
else{
//maps[i][j] = key;
if(j == 1){
a.add(paths.get(i).get(j));
}
map.put(paths.get(i).get(j), 1);
//map2.put(key++, paths.get(i).get(j));
}
}
}
//System.out.println(a);
for(int i = 0; i<a.size(); i++){
if(map.get(a.get(i)) == 1){
return a.get(i);
}
}
return "";
}
}