forked from srinathr91/TestJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
36 lines (32 loc) · 1021 Bytes
/
Solution.java
File metadata and controls
36 lines (32 loc) · 1021 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
34
35
36
import java.io.*;
import java.util.*;
public class Solution {
public static int isPalindrome(String p){
int i=0;
int j=p.length()-1;
while(i<=j){
if(p.charAt(i)!=p.charAt(j)){
if((p.charAt(i+1)==p.charAt(j))&&(p.charAt(i+2)==p.charAt(j-1))){
return i;
}else if((p.charAt(i)==p.charAt(j-1))&&(p.charAt(i+1)==p.charAt(j-2))){
return j;
}else{
return i;
}
}
i++;
j--;
}
return -1;
}
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
sc.nextLine();
for(int b=0;b<a;b++){
String st=sc.nextLine();
System.out.println(Solution.isPalindrome(st));
}
}
}