Clean Java Solution


  • 0
    S
    public class Solution {
        public boolean isPalindrome(String s) 
        {
            s = s.toLowerCase();
            int i =0,j=s.length()-1;
            while(i<j)
            {
                if(s.charAt(i)!=s.charAt(j) && (Character.isLetterOrDigit(s.charAt(i))) && (Character.isLetterOrDigit(s.charAt(j)))) 
                    return false;
                    else {
                    if(!(Character.isLetterOrDigit(s.charAt(i)))) i++;
                    else if(!(Character.isLetterOrDigit(s.charAt(j)))) j--;
                    else{
                            i++;j--;
                    }
                }
            }
            return true;
            
        }
    }
    

Log in to reply
 

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