Simple/Clean Java Solution :)


  • 0
    S
    public class Solution {
        public boolean isPalindrome(String s) {
            s = s.replaceAll("[^a-zA-Z0-9]", "");
            s = s.toLowerCase();
            int j = s.length()-1;
            int i = 0;
            while(i<j) {
                if(s.charAt(i++) != s.charAt(j--)) {
                    return false;
                }
            }
            return true;
        }
    }

Log in to reply
 

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