12ms C solution


  • 0
    V
    int firstUniqChar(char* s)
    {
        int count[26];
        int i;
    
        for (i = 0; i < 26; i++)
            count[i] = 0;
    
        for (i = 0; s[i] != '\0'; i++)
            count[s[i] - 'a']++;
    
        for (i = 0; s[i] != '\0'; i++)
            if (count[s[i] - 'a'] == 1)
                return i;
    
        return -1;
    }
    

Log in to reply
 

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