My solutions, 5 ms


  • 0
    E

    public class Solution {
    public boolean isPalindrome(String s) {
    if(s.length() < 1) return true;
    char[] ch = s.toCharArray();
    for(int i = 0;i < ch.length;i ++){
    if(ch[i] >='A' && ch[i] <= 'Z'){
    ch[i] = (char)(ch[i] - 'A' + 'a');
    }
    }
    int low = 0, high = ch.length -1;
    while(low < high){
    if((ch[low] < 'a' || ch[low] > 'z') && (ch[low] < '0' || ch[low] > '9')){
    low ++;
    continue;
    }
    if((ch[high] < 'a' || ch[high] > 'z')&&(ch[high] < '0' || ch[high] > '9')){
    high --;
    continue;
    }
    if(ch[low] != ch[high]) {
    return false;
    }
    low ++;
    high --;
    }
    return true;
    }
    }


Log in to reply
 

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