Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Find duplicates in a given integer 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 [] arr = new int []{1,3,3,4,4,5,6,7,8,8,9}; findduplicates(arr); } public static void findduplicates(int[] a) { Dictionary<int,int> dict = new Dictionary<int,int>(); dict.Add(a[0],1); for(int i=1; i< a.Length; i++) { if(dict.ContainsKey(a[i])) { dict[a[i]]++; } else { dict.Add(a[i],1); } } foreach(KeyValuePair<int,int> dic in dict) { if(dic.Value >1) Console.WriteLine(dic.Key); } } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
findrotations
Sum Matrix Main Diagonal
Can a == true && a == false be true in C#?
Project1
P.I. Works
BiologyQuestions
Student Cables
decimal to binary conversion
Ok
to find the first index of a substring in a given string
stackse - search stackoverflow differently
Please log in to post a comment.