Java 4ms


  • 0
    public class Solution {
        public boolean isPalindrome(String s) {
            char[] ss = s.toCharArray();
            for (int i = 0, j = ss.length - 1; i < j; i++, j--) {
                if ((ss[i] < 'A' || (ss[i] > 'Z' && ss[i] < 'a') || ss[i] > 'z') && (ss[i] < '0' || ss[i] > '9')) {
                    j++;
                    continue;
                }
                if ((ss[j] < 'A' || (ss[j] > 'Z' && ss[j] < 'a') || ss[j] > 'z') && (ss[j] < '0' || ss[j] > '9')) {
                    i--;
                    continue;
                }
                if ('A' <= ss[i] && ss[i] <= 'Z') {
                    ss[i] += 32;
                }
                if ('A' <= ss[j] && ss[j] <= 'Z') {
                    ss[j] += 32;
                }
                if (ss[i] != ss[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.