C++ simple solution - 45ms


  • 0
    J
    class Solution {
    public:
        int firstUniqueChar(int *array, string s){
            for(int i=0; i<s.length(); i++){
                if(array[s[i]] == 1) 
                    return i;
            }
            return -1;
        }
        
        int firstUniqChar(string s) {
            int array[256] = {0};
            for(char c : s){
                array[c]++;
            }
            return firstUniqueChar(array, s);
        }
    };
    

Log in to reply
 

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