java o(n)


  • 0
    Y

    public class Solution {
    public int longestPalindrome(String s) {
    int len = 0;
    int [] dict = new int['z'+1];
    for (int i=0; i<s.length(); i++) {
    dict[s.charAt(i)]++;
    }
    for (int i='A'; i<='z'; i++) {
    len += (dict[i]/2)*2;
    }
    if (len != s.length())
    len++;
    return len;
    }
    }


Log in to reply
 

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