-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIterniry.java
More file actions
37 lines (28 loc) · 870 Bytes
/
Iterniry.java
File metadata and controls
37 lines (28 loc) · 870 Bytes
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
import java.util.*;
public class Iterniry {
public static String getStart(HashMap<String,String>ticket){
HashMap<String,String> revMap=new HashMap<>();
for(String key:ticket.keySet()){
revMap.put(ticket.get(key),key);
}
for(String key:ticket.keySet()){
if(!revMap.containsKey(key)){
return key;
}
}
return null;
}
public static void main(String args[]){
HashMap<String,String> map=new HashMap<>();
map.put("chennai","Bengaluru");
map.put("Mumbai","Delhi");
map.put("Goa","chennai");
map.put("Delhi","Goa");
String start=getStart(map);
while(map.containsKey(start)){
System.out.print(start + "->");
start=map.get(start);
}
System.out.println(start);
}
}