-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMikeAndPalindrome.java
More file actions
49 lines (41 loc) · 985 Bytes
/
MikeAndPalindrome.java
File metadata and controls
49 lines (41 loc) · 985 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
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class MikeAndPalindrome
{
public static void main( String[] args )
{
Scanner s = new Scanner( System.in );
String word = s.next();
int n = word.length();
int count=0;
int mid = n/2;
int l=0,r=0;
if(n%2==0)
{
l = mid-1;
r= mid;
}
else
{
l =mid-1;
r= mid+1;
}
while(l>=0 && r<n)
{
if(word.charAt( l-- )!=word.charAt( r++ ))
{
count++;
if(count==2)
break;
}
}
if(n%2!=0 && count==0)
count=1;
if(count==1 )
System.out.println( "YES" );
else
System.out.println( "NO" );
}
}