c 9ms


  • 0
    C

    int firstUniqChar(char* s) {
    int c[26]={0};
    int i=0;
    while(s[i])
    {
    ++c[s[i++]-'a'];
    }
    i=0;
    while(s[i])
    {
    if(c[s[i++]-'a']==1)
    {
    return i-1;
    }
    }
    return -1;
    }


Log in to reply
 

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