Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome&nbsp;that can be built with those letters.

Letters are case sensitive, for example,&nbsp;"Aa" is not considered a palindrome here.

&nbsp;
Example 1:

Input: s = "abccccdd"
Output: 7
Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7.


Example 2:

Input: s = "a"
Output: 1
Explanation: The longest palindrome that can be built is "a", whose length is 1.


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 2000
	s consists of lowercase and/or uppercase English&nbsp;letters only.


class Solution:
    def longestPalindrome(self, s: str) -> int:
        letters = {} 
        for letter in s: #count each letter and update letters dict
            if letter in letters:
                letters[letter] += 1
            else:
                letters[letter] = 1
        
        
        plus1 = 0 # if there is a letter with count of odd ans must +=1 
        ans = 0
        for n in letters.values():
            if n == 1: #1 can only appear in the middle of our word
                plus1 = 1
            elif n%2 == 0:
                ans += n
            else:
                ans += n - 1
                plus1 = 1
                
        return ans + plus1
class Solution {
    public int longestPalindrome(String s) {
        HashMap<Character, Integer> map = new HashMap<>();

        int evenNo = 0;
        int oddNo = 0;

        for ( int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (map.containsKey(c)) {
                map.put(c, map.get(c) + 1);
            } else {
                map.put(c, 1);
            }

        }
        for (Map.Entry e : map.entrySet()) {
            int n = (int) e.getValue();
            if (n % 2 != 0) {
                oddNo += n;
            }
            evenNo += (n / 2) * 2;
        }

        if (oddNo > 0) {
            evenNo += 1;
        }
        return evenNo;
    }
}
class Solution {
public:
    int longestPalindrome(string s) {
        map<char,int> mp;
        for(int i=0;i<s.length();i++){
            mp[s[i]]++;
        }
        int ans = 0;
        int odd = 0;
        for(auto i:mp){
            if(i.second % 2 == 1){
                odd = 1;
            }
            ans = ans + (i.second/2)*2;
        }
        return ans+odd;
    }
};
var longestPalindrome = function(s) {
    const hashMap = {};
    let ouput = 0;
    let hashOdd = false;

    for (let i = 0; i < s.length; i++) {
        if (!hashMap[s[i]]) {
            hashMap[s[i]] = 0;
        }
        hashMap[s[i]] += 1;
    }

    Object.values(hashMap)?.forEach(character => {
        ouput += character%2 ? character - 1 : character;
        if (character%2 && !hashOdd) {
            hashOdd = true;
        }
    });

    return ouput + (hashOdd ? 1 : 0);
};
Longest Palindrome