3-ms,3-lines,c


  • 0
    W
    int longestPalindrome(char* s) {
        int hash[256] = {0}, ans = 0;
        for(int i = 0; s[i]; i++) ans += (++hash[s[i]]) % 2 == 0 ? 2 : 0;
        return ans + (strlen(s) > ans);
    }
    

Log in to reply
 

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