Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- namespace ConsoleApp10
- {
- public static class RemoveDuplicates
- {
- public static void Remove(int[] array)
- {
- var hashSet = new HashSet<int>();
- var j = 0;
- for (var i = 0; i < array.Length; i++)
- {
- if (!hashSet.Contains(array[i]))
- {
- hashSet.Add(array[i]);
- array[j++] = array[i];
- }
- }
- //set -1 for removed duplicates
- while (j < array.Length)
- {
- array[j++] = -1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement