Skip to content

Commit 5d47b47

Browse files
Create String Palidrom.java
1 parent 6e24eed commit 5d47b47

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

String Palidrom.java

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Kumar has been given a string and asked to determine whether it can be converted into a palindrome after removing at most one characte
3+
4+
Input Format
5+
6+
str="abcbea"
7+
8+
Constraints
9+
10+
1<=Str.length<=10^3 Str consists of Lowercase English characters
11+
12+
Output Format
13+
14+
true
15+
16+
Sample Input 0
17+
18+
abceba
19+
Sample Output 0
20+
21+
true
22+
Explanation 0
23+
24+
you can remove character 'e' to make it palindrome
25+
*/
26+
import java.io.*;
27+
import java.util.*;
28+
29+
public class Solution {
30+
31+
public static void main(String[] args) {
32+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
33+
Scanner sc = new Scanner(System.in);
34+
String s = sc.next();
35+
String r = "";
36+
37+
for(int i=0;i<s.length();i++)
38+
{
39+
char ch = s.charAt(i);
40+
r = ch+r;
41+
}
42+
boolean check = true;
43+
int count = 0;
44+
int i=0;
45+
46+
for(i=0;i<s.length();i++)
47+
{
48+
49+
if((s.charAt(i)!=r.charAt(i)))
50+
count++;
51+
}
52+
if(count > 2)
53+
{
54+
check = false;
55+
56+
}
57+
System.out.print(check);
58+
}
59+
}

0 commit comments

Comments
 (0)