Skip to content

Instantly share code, notes, and snippets.

@vinay13
Created August 27, 2014 21:39
Show Gist options
  • Save vinay13/789332e28e70439945c8 to your computer and use it in GitHub Desktop.
Save vinay13/789332e28e70439945c8 to your computer and use it in GitHub Desktop.
first non-repeating character in a string
//first non repeating chaarcter in a string
#include <stdio.h>
#include <string.h>
char firstNon(char str[])
{
int count[256]={0};
int i;
for(i=0;i<strlen(str);i++)
count[str[i]]++;
for(i=0;i<strlen(str);i++)
{
if(count[str[i]]==1)
return str[i];
}
}
int main()
{
char str[]="adbabc";
char ans=firstNon(str);
printf("%c ",ans );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment