I have to ignore all special characters in the string.I have created a new string s1 including only alphanumerics characters.Then,made a reverse string s2 and then checked if they are pallindrome or not.
class Solution
{
public boolean isPalindrome(String s)
{
char c,ch;
String s1="";
String s2="";
s=s.trim();
s=s.toLowerCase();
if(s=="")
return true;
for(int i=0;i<s.length();i++)
{
c=s.charAt(i);
if(c>=97&&c<=122||c>=0&&c<=9)
s1=s1+c;
}
for(int j=s1.length()-1;j>=0;j--)
{
ch=s1.charAt(j);
s2=s2+ch;
}
if(s1.equals(s2))
return true;
else
return false;
}
}