c++ O(n) solution


  • 0
    M
    int firstUniqChar(string s) {
        int count[26] = {0};
        for( int i=0 ; i<s.length() ; i++){
            count[s[i]-97] ++ ;
        }
        for( int i=0 ; i<s.length() ; i++){
            if(count[s[i]-97] == 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.