Solution - Java - 10ms


  • 0
    A
    public class Solution 
    {
        public boolean isPalindrome(String s) 
        {
            StringBuilder str = new StringBuilder();
            for(int i=0; i<s.length(); i++)
            {
                char ch = s.charAt(i);
                if((ch>=48 && ch<=57) || (ch>=65 && ch<=90) || (ch>=97 && ch<=122))
                {
                    if(ch>=65 && ch<=90)
                        str.append((char)(ch+32));
                    else
                        str.append(ch);
                }
            }
            String str1 = str.toString();
            String str2 = str.reverse().toString();
            return str1.equals(str2);
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.