-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram2.java
More file actions
80 lines (52 loc) · 1.43 KB
/
program2.java
File metadata and controls
80 lines (52 loc) · 1.43 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Input : str = "abaab"
Output: 3
Explanation :
All palindrome substring are :
"aba" , "aa" , "baab"
Input : str = "abbaeae"
Output: 4
Explanation :
All palindrome substring are :
"bb" , "abba" ,"aea","eae"
*/
package LeetCode_String;
import java.util.ArrayList;
public class program2 {
static String noPalindrome(String str){
String s="";
ArrayList<String>st = new ArrayList<String>();
for(int i=0;i<=str.length();i++){
for(int j=i+1;j<=str.length();j++){
st.add(str.substring(i, j));
}
}
System.out.print(st+" ");
int max = 0;
for(int i=0;i<st.size();i++){
String substr = st.get(i);
int left = 0;
int right = substr.length()-1;
boolean flag = true;
while(left<right){
if(substr.charAt(left)!=substr.charAt(right)){
flag = false;
break;
}
left++;
right--;
}
if(flag){
if(max < substr.length()){
s = substr;
max = substr.length();
}
}
}
return s ;
}
public static void main(String[] args) {
String str = "a";
System.out.println(noPalindrome(str));
}
}