Java Solution - 13ms


  • 0
    S
    public class Solution {
        public boolean isPalindrome(String s) {
            char []a = s.toCharArray();
            int len = s.length();
            System.out.println(s);
            int i=0;
            int j=len-1;
            while(i<j) {
                while (i<j && !((a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z') || (a[i] >= '0' && a[i] <= '9'))) {
                    i++;
                }
                while (i<j && !((a[j] >= 'a' && a[j] <= 'z') || (a[j] >= 'A' && a[j] <= 'Z') || (a[j] >= '0' && a[j] <= '9'))) {
                    j--;
                }
                Character temp1 = Character.toLowerCase(a[i]);
                Character temp2 = Character.toLowerCase(a[j]);
                if (temp1 != temp2) {
                    return false;
                }
                i++;
                j--;
            }
            return true;
        }
    }
    

Log in to reply
 

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