Printing the duplicate element of a string using hashing
Time Complexity O(n)
#include <iostream>
#include <set>
#include<string.h>
using namespace std;
int main ()
{
char arr[100];
std::set<char>myset;
printf("Enter the String\n");
scanf("%s",arr);
int i;
for(i=0;i<strlen(arr);i++)
{
if(myset.count(arr[i])==0)
{
myset.insert(arr[i]);
}
else
{
printf("%c",arr[i]);
}
}
return 0;
}
No comments:
Post a Comment