18 lines C accepted 3ms


  • 0
    J

    int longestPalindrome(char* s) {
    int asccii[256] = {0};
    int res = 0;
    int getood = 0;
    while(*s != '\0'){
    asccii[*s++]++;
    }
    for(int i = 0; i < 256; i++){
    if(getood == 0 && asccii[i] % 2 == 1){
    res += asccii[i];
    getood = 1;
    }
    else{
    res += ((asccii[i]>>1)<<1);
    }
    }
    return res;
    }


Log in to reply
 

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