JavaScript solution with a single for loop
We don\'t have to make an additional loop through keys.\n\n\nvar longestPalindrome = function(s) {\n  let ans = 0;\n  let keys = {};\n  \n  for (let char of s) 
We don\'t have to make an additional loop through keys.\n\n```\nvar longestPalindrome = function(s) {\n  let ans = 0;\n  let keys = {};\n  \n  for (let char of s) {\n    keys[char] = (keys[char] || 0) + 1;\n    if (keys[char] % 2 == 0) ans += 2;\n  }\n  return s.length > ans ? ans + 1 : ans;\n};\n```
['JavaScript']