using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace TestAlgo { class Program { static void Main(string[] args) { ArrayCls objcls = new ArrayCls(); objcls.FindDuplicateNo(); } }
--------------------------
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace TestAlgo { public class ArrayCls { public void FindDuplicateNo() { int[] intArr = new int[] { 6,5,2,9,2}; Hashtable hash = new Hashtable(); for (int i = 0; i < intArr.Count(); i++) { int counter=1; if (hash.ContainsKey(intArr[i])) { int c =Convert.ToInt32( hash[intArr[i]]); hash[intArr[i]] = c + 1; } else hash.Add(intArr[i],counter); } ICollection k = hash.Keys; foreach(int j in k) { if (Convert.ToInt32(hash[j]) > 1) Console.WriteLine(j); } //hash.Add(); } } }
No comments:
Post a Comment