Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #include <iostream>
- using namespace std;
- char *removeDuplicate(char str[], int n) {
- // Used as index in the modified string
- int index = 0;
- // Traverse through all characters
- for (int i = 0; i < n; i++) {
- // Check if str[i] is present before it
- int j;
- for (j = 0; j < i; j++) {
- if (str[i] == str[j]) {
- break;
- }
- }
- // If not present, then add it to result.
- if (j == i) {
- str[index++] = str[i];
- }
- }
- return str;
- }
- // Driver code
- int main() {
- char str[] = "geeksforgeeks";
- int n = strlen(str) + 1;
- cout << removeDuplicate(str, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement