Created
September 2, 2016 08:55
-
-
Save devpruthvi/f6736459a648c3a7b0247d7641ce759b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import java.text.*; | |
import java.math.*; | |
import java.util.regex.*; | |
public class temp | |
{ | |
public static void main(String[] args) | |
{ | |
String str=(new Scanner(System.in)).nextLine(); | |
if(str.length() == 1) { | |
System.out.println(str); | |
return; | |
} | |
System.out.println(longestSubstr(str)); | |
} | |
public static String longestSubstr(String s) | |
{ | |
String result=""; | |
int len=s.length(); | |
for(int i=len/2; i>0; i--) | |
{ | |
String front=s.substring(0,i); | |
String end=s.substring(len-i); | |
if(front.equals(end)) | |
{ | |
result=front; | |
break; | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment