-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion30.java
More file actions
33 lines (29 loc) · 978 Bytes
/
question30.java
File metadata and controls
33 lines (29 loc) · 978 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
public class question30{
public static boolean validispalindrome(String sc) {
int left = 0, right = sc.length() - 1;
while(left < right){
if(sc.charAt(left) != sc.charAt(right)){
return (ispalindrome(sc,left + 1,right) || ispalindrome(sc,left,right-1));
}
left++;
right--;
}
return true;
}
public static boolean ispalindrome(String sc,int left, int right) {
while(left < right){
if(sc.charAt(left) != sc.charAt(right))return false;
left++;
right--;
}
return true;
}
public static void main(String[] args) {
String s1 = "abc";
System.out.println(validispalindrome(s1));
String s2 = "level";
System.out.println(validispalindrome(s2));
String s3 = "abc";
System.out.println(validispalindrome(s3));
}
}