Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void PrintDuplicates(int[] arr)
- {
- if (arr == null)
- throw new ArgumentException("arr can't be null.");
- Hashtable table = new Hashtable();
- for (int i = 0; i < arr.Length; i++)
- {
- if (table.ContainsKey(arr[i]) == true)
- {
- // Console.WriteLine(i);
- }
- else
- {
- table.Add(arr[i], "");
- }
- }
- }
- void PrintDuplicatesWithSort(int[] arr)
- {
- if (arr == null)
- throw new ArgumentException("arr can't be null.");
- arr.ToList().Sort();
- for (int i = 0; i < arr.Length - 1; i++)
- {
- if (arr[i] == arr[i + 1])
- {
- // Console.WriteLine(i);
- }
- }
- }
Add Comment
Please, Sign In to add comment