Advertisement
Guest User

Untitled

a guest
May 27th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System.Collections.Generic;
  2. namespace ConsoleApp10
  3. {
  4.     public static class RemoveDuplicates
  5.     {
  6.         public static void Remove(int[] array)
  7.         {
  8.             var hashSet = new HashSet<int>();
  9.             var j = 0;
  10.             for (var i = 0; i < array.Length; i++)
  11.             {
  12.                 if (!hashSet.Contains(array[i]))
  13.                 {
  14.                     hashSet.Add(array[i]);
  15.                     array[j++] = array[i];
  16.                 }
  17.             }
  18.             //set -1 for removed duplicates
  19.             while (j < array.Length)
  20.             {
  21.                 array[j++] = -1;
  22.             }
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement