1let chars = ['A', 'B', 'A', 'C', 'B'];
2let uniqueChars = [...new Set(chars)];
3
4console.log(uniqueChars);
5
6output:
7[ 'A', 'B', 'C' ]
1// Java
2public int removeDuplicates(int[] nums) {
3 if (nums.length == 0) return 0;
4 int i = 0;
5 for (int j = 1; j < nums.length; j++) {
6 if (nums[j] != nums[i]) {
7 i++;
8 nums[i] = nums[j];
9 }
10 }
11 return i + 1;
12}
1# function for removing duplicates
2def removeDuplicate(arr, n):
3 j = 0
4
5 # traverse elements of arr
6 for i in range(0, n-1):
7 # if ith element is not equal to (i+1)th element, then store ith value in arr[j]
8 if (arr[i] != arr[i+1]):
9 arr[j] = arr[i]
10 j = j+1
11
12 # store last value of arr in arr[j]
13 arr[j] = arr[n-1]
14 j = j+1
15
16 # print first j elements of array arr
17 for i in range(0, j):
18 print("%d"%(arr[i]), end = " ")
19
20arr = [1, 3, 5, 5, 7, 9]
21n = len(arr)
22# calling function when number of elements in array is greater than 1
23if (n > 1):
24 removeDuplicate(arr, n)
25
1def remove_duplicates(nums: [int]) -> int:
2 cnt = 1
3 for index in range(len(nums) - 1):
4 if nums[index] != nums[index + 1]:
5 nums[cnt] = nums[index + 1]
6 cnt += 1
7 print(cnt)
1def remove_duplicate(nums: [int]) -> int:
2 nums[:] = sorted(set(nums))
3 return len(nums)
1j = 0
2
3// traverse elements of arr
4for i=0 to n-2
5 // if ith element is not equal to (i+1)th element of arr, then store ith value in arr[j]
6 if arr[i] != arr[i+1]
7 arr[j] = arr[i]
8 j += 1
9
10// store last value of arr in temp
11arr[j] = arr[n-1]
12j += 1
13
14// print first j elements of array arr
15for i=0 to j-1
16 print arr[i]
17