Skip to content

Commit b1dba25

Browse files
authored
Create Destination City
1 parent aafbd72 commit b1dba25

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Destination City

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Solution {
2+
public String destCity(List<List<String>> paths) {
3+
Map<String, Integer> map = new HashMap<>();
4+
//Map<Integer, String> map2 = new HashMap<>();
5+
//int[][] maps = new int[paths.size()][paths.get(0).size()];
6+
int key = 1;
7+
List<String> a = new ArrayList<>();
8+
for(int i = 0; i<paths.size(); i++){
9+
for(int j = 0; j<2; j++){
10+
if(map.containsKey(paths.get(i).get(j))){
11+
map.replace(paths.get(i).get(j), map.get(paths.get(i).get(j))+1);
12+
}
13+
else{
14+
//maps[i][j] = key;
15+
if(j == 1){
16+
a.add(paths.get(i).get(j));
17+
}
18+
map.put(paths.get(i).get(j), 1);
19+
//map2.put(key++, paths.get(i).get(j));
20+
}
21+
}
22+
}
23+
//System.out.println(a);
24+
for(int i = 0; i<a.size(); i++){
25+
if(map.get(a.get(i)) == 1){
26+
return a.get(i);
27+
}
28+
}
29+
30+
31+
return "";
32+
}
33+
}

0 commit comments

Comments
 (0)