C ++ 36ms


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