Duplicate element of a string using hashing O(n)

Printing the duplicate element of a string using hashing
Time Complexity O(n) 



#include<stdio.h>
#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

All Repeated Words In Text File And Their Occurrences In Java

Find All Repeated Words In Text File And Their Occurrences In Java Place your file location in the argument of the FileReader. If t...