Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Find Max Number Of Occurences in an int array
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { int[] sample = { 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 11, 12, 13, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; Console.WriteLine("Max = {0}", FindMaxNumberOfOccurence(sample)); } public static int FindMaxNumberOfOccurence(int[] sample) { Dictionary<int, int> dict = new Dictionary<int, int>(); foreach (var item in sample) { if (!dict.Keys.Contains(item)) { dict.Add(item, 1); } else dict[item] += 1; } return dict.FirstOrDefault(x => x.Value == dict.Values.Max()).Key; } } }
run
|
edit
|
history
|
help
0
C# - a method that accepts an indefinite number of parameters
asxasdxsd
quick sort final
Sri 19 Sept
Punnet Square Generator
IEquatable doubt resolved!!
recursion
azsdfghju654 ffddfdf
a.out
fuck this