-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanBeMadePalindrome.java
More file actions
52 lines (43 loc) · 1.1 KB
/
Copy pathCanBeMadePalindrome.java
File metadata and controls
52 lines (43 loc) · 1.1 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
import java.util.Scanner;
class Solution
{
public boolean validPalindrome(String s)
{
int i=0;
int j = s.length()-1;
while(i<j)
{
if(s.charAt(i) != s.charAt(j))
{
return (isPalin(s, i+1, j) || isPalin(s, i, j-1));
}
i++;
j--;
}
return true;
}
public boolean isPalin(String str, int i, int j)
{
while(i<j)
{
if(str.charAt(i++) != str.charAt(j--))
{
return false;
}
}
return true;
}
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
if(validPalindrome(str))
{
System.out.println("Yes, we can make the string palindrome by deleting atmost one character.");
}
else
{
System.out.println("No, we can make the string palindrome by deleting atmost one character.");
}
}
}