Guest User

Untitled

a guest
Feb 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. void PrintDuplicates(int[] arr)
  2. {
  3. if (arr == null)
  4. throw new ArgumentException("arr can't be null.");
  5.  
  6. Hashtable table = new Hashtable();
  7.  
  8. for (int i = 0; i < arr.Length; i++)
  9. {
  10. if (table.ContainsKey(arr[i]) == true)
  11. {
  12. // Console.WriteLine(i);
  13. }
  14. else
  15. {
  16. table.Add(arr[i], "");
  17. }
  18. }
  19. }
  20.  
  21. void PrintDuplicatesWithSort(int[] arr)
  22. {
  23. if (arr == null)
  24. throw new ArgumentException("arr can't be null.");
  25.  
  26. arr.ToList().Sort();
  27.  
  28. for (int i = 0; i < arr.Length - 1; i++)
  29. {
  30. if (arr[i] == arr[i + 1])
  31. {
  32. // Console.WriteLine(i);
  33. }
  34. }
  35. }
Add Comment
Please, Sign In to add comment