mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 13:31:21 +03:00
13 lines
259 B
C
13 lines
259 B
C
int firstUniqChar(char *s)
|
|
{
|
|
int *arr = calloc(256, sizeof(int));
|
|
int i;
|
|
for (i = 0; i < strlen(s); i++) arr[s[i]] = arr[s[i]] + 1;
|
|
for (i = 0; i < strlen(s); i++)
|
|
{
|
|
if (arr[s[i]] == 1)
|
|
return i;
|
|
}
|
|
return -1;
|
|
}
|