https://leetcode.com/problems/longest-palindrome/submissions/
/**
* @param {string} s
* @return {number}
*/
var longestPalindrome = function (s) {
let longest = 0;
let keys = {};
for (const char of s) {
keys[char] = (keys[char] || 0) + 1;
if (keys[char] % 2 === 0) {
longest += 2;
}
}
return s.length > longest ? longest + 1 : longest;
};
Runtime: 106 ms, faster than 58.34% of JavaScript online submissions for Longest Palindrome.
Memory Usage: 43.5 MB, less than 73.08% of JavaScript online submissions for Longest Palindrome.