Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. string removeDuplicate(string str, int n) {
  6. // Used as index in the modified string
  7. int index = 0;
  8. int j;
  9. int size=0;
  10. // Traverse through all characters
  11. for (int i = 0; i < n; i++) {
  12. // Check if str[i] is present before it
  13. for (j = 0; j < i; j++) {
  14. if (str[i] == str[j]) {
  15. break;
  16. }
  17. }
  18. // If not present, then add it to result.
  19. if (j == i) {
  20. str[index++] = str[i];
  21. size++;
  22. }
  23. }
  24. str = str.substr(0,size);
  25. return str;
  26. }
  27.  
  28. // Driver code
  29. int main() {
  30. string str = "geeksforgeeks";
  31. int n = str.length() ;
  32. cout << removeDuplicate(str, n);
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement