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
Tarkov Time
matching parenthesis
Delegate test lambda
line 1 syntax error
GeneGenerator
dgh ret ertfh fhf hft85487
Byte array to base 64 string
give coins
ReRoute Emails
C# program to Determine if Two Words Are Anagrams of Each Other