public class Solution {
    public int[] SingleNumber(int[] nums) {
        var dic = new Dictionary<int, int>();
            foreach (var num in nums)
            {
                if (!dic.ContainsKey(num))
                {
                    dic.Add(num, 1);
                }
                else
                {
                    dic[num]++;
                }
            }
            var list = dic.OrderBy(x => x.Value).ToList();
            var ary = new int[2];
            ary[0] = list[0].Key;
            ary[1] = list[1].Key;

            return ary;
    }
}

https://leetcode.com/problems/single-number-iii/#/description

posted on 2017-05-09 16:36  Sempron2800+  阅读(103)  评论(0编辑  收藏  举报