public class Solution { public int LongestPalindrome(string s) { var dic = new Dictionary<char, int>(); foreach (var c in s) { if (!dic.ContainsKey(c)) { dic.Add(c, 1); } else { dic[c]++; } } int len = 0; foreach (var d in dic) { len += (d.Value / 2) * 2; } return len == s.Length ? len : len + 1; } }
https://leetcode.com/problems/longest-palindrome/#/description