My Java Solutions 4ms


  • 0
    N

    public boolean isPalindrome(String s){
    if(s==null||s.isEmpty()||s.length()==1)
    return true;
    char[] sArr = s.toCharArray();
    int length = sArr.length;
    int temp = 0;
    for(int i=0;i<length;i++){
    if(sArr[i]>='A'&&sArr[i]<='Z')
    sArr[temp++]=(char)((sArr[i]-'A')+'a');
    else if(sArr[i]>='a'&&sArr[i]<='z')
    sArr[temp++]=sArr[i];
    else if (sArr[i]>='0'&&sArr[i]<='9')
    sArr[temp++]=sArr[i];
    }
    int start =0,end = temp-1;
    while(start<end){
    if(sArr[start]!=sArr[end])
    return false;
    start++;end--;
    }
    return true;

    }


Log in to reply
 

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