Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 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.   // Traverse through all characters
  9.   for (int i = 0; i < n; i++) {
  10.     // Check if str[i] is present before it
  11.     int j;
  12.     for (j = 0; j < i; j++) {
  13.       if (str[i] == str[j]) {
  14.         break;
  15.       }
  16.     }
  17.     // If not present, then add it to result.
  18.     if (j == i) {
  19.       str[index++] = str[i];
  20.     }
  21.   }
  22.   return str;
  23. }
  24.  
  25. // Driver code
  26. int main() {
  27.   string str = "geeksforgeeks";
  28.   int n = str.length() + 1;
  29.   cout << removeDuplicate(str, n);
  30.   return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement