Skip to content

Commit d17c0c2

Browse files
authored
Create HamiltonianPath.java
1 parent dba717e commit d17c0c2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Hard/HamiltonianPath.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
class Main {
5+
6+
public static String HamiltonianPath(String[] strArr) {
7+
// code goes here
8+
String str= strArr[2].toString();
9+
String strc= strArr[1].toString();
10+
String hp="";
11+
12+
String strnew= str.replaceAll(",","").replace("(","").replace(")","");
13+
for(int i=0;i<strnew.length()-1;i++){
14+
15+
if(strc.contains(strnew.charAt(i)+"-"+strnew.charAt(i+1))||strc.contains(strnew.charAt(i+1)+"-"+strnew.charAt(i))){
16+
continue;
17+
}
18+
else{
19+
hp=strnew.charAt(i)+"";
20+
return hp;
21+
}
22+
23+
}
24+
25+
26+
return "yes";
27+
}
28+
29+
public static void main (String[] args) {
30+
// keep this function call here
31+
Scanner s = new Scanner(System.in);
32+
System.out.print(HamiltonianPath(s.nextLine()));
33+
}
34+
35+
}

0 commit comments

Comments
 (0)