Can any one explain why can't my solution pass the OJ? I think I have the similar method compared to yours.


  • 0
    B

    Can any one explain why can't my solution pass the OJ? I think I have the similar method compared to yours.
    '''
    class Solution {
    public:
    int longestPalindrome(string s) {
    int arr[52] = {0};
    int len = s.size();
    for(int i = 0;i < len;++i){
    if(isupper(s[i])){
    ++arr[s[i]-'A'];
    }
    else if(islower(s[i])){
    ++arr[(s[i]-'a')+26];
    }
    }
    len = 0;
    int max = 0;
    for(int i = 0;i < 52;++i){
    if(arr[i]%2 == 0){
    len += arr[i];
    }
    else{
    if(arr[i] > max){
    max = arr[i];
    }
    }
    }
    return len+max;
    }
    };
    ''''
    Thanks a lot!


Log in to reply
 

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