Advertisement
Guest User

Untitled

a guest
May 27th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. using System;
  2. namespace ConsoleApp10
  3. {
  4.     public class RemoveDuplicatesSort
  5.     {
  6.         public void Remove(int[] array)
  7.         {
  8.             if (array == null)
  9.             {
  10.                 throw new ArgumentException("Array is empty");
  11.             }
  12.             Array.Sort(array);
  13.             int j = 0;
  14.             for (var i = 0; i < array.Length; i++)
  15.             {
  16.                 if (i == array.Length - 1 || array[i] != array[i + 1])
  17.                 {
  18.                     array[j++] = array[i];
  19.                 }
  20.             }
  21.             while (j < array.Length)
  22.             {
  23.                 array[j++] = -1;
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement