File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments