mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
12 lines
260 B
C
12 lines
260 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;
|
|
}
|