public class Solution { public int MajorityElement(int[] nums) { Dictionarydic = new Dictionary (); var len = nums.Length; for (int i = 0; i < len; i++) { if (!dic.ContainsKey(nums[i])) { dic.Add(nums[i], 1); } else { dic[nums[i]]++; } } var result = 0; foreach (var d in dic) { if (d.Value > len / 2) { result = d.Key; break; } } return result; }}