C solution 12ms


  • 0
    A

    int firstUniqChar(char* s) {

    int i,size,uni_index,array[2][26]={};
    
    for (i=0;*(s+i)!='\0';i++)
        array[0][*(s+i)-'a']++,array[1][*(s+i)-'a']=i;
    uni_index=i;
    size=i;
    for (i=0;i<26;i++)
        if (array[0][i]==1 && array[1][i]<uni_index)
            uni_index=array[1][i];
    
    if (uni_index<size)
        return uni_index;
    else
        return -1;
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.