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

posted on 2017-04-19 11:22  Sempron2800+  阅读(108)  评论(0编辑  收藏  举报