fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int removeDuplicates(int arr[], int n)
  5. {
  6. int i = 0;
  7. for (int j = 1; j < n; j++) {
  8. if (arr[i] != arr[j]) {
  9. i++;
  10. arr[i] = arr[j];
  11. }
  12. }
  13. return i + 1;
  14. }
  15. int main() {
  16. int arr[] = {1,1,2,2,2,3,3};
  17. int n = sizeof(arr)/sizeof(arr[0]);
  18. int k = removeDuplicates(arr, n);
  19. cout << "The array after removing duplicate elements is " << endl;
  20. for (int i = 0; i < k; i++) {
  21. cout << arr[i] << " ";
  22. }
  23. }
Success #stdin #stdout 0s 5264KB
stdin
Standard input is empty
stdout
The array after removing duplicate elements is 
1 2 3