Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d17c0c2

Browse filesBrowse files
authored
Create HamiltonianPath.java
1 parent dba717e commit d17c0c2
Copy full SHA for d17c0c2

File tree

Expand file treeCollapse file tree

1 file changed

+35
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+35
-0
lines changed

‎Hard/HamiltonianPath.java

Copy file name to clipboard
+35Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.