C++ 36ms. beats 97.45%


  • 0
    W

    '''
    int firstUniqChar(std::string s) {

        int index=-1 ,count = 1;
        int temp = INT_MAX;
        
    	std::vector<int> vec(26) ;
        std::vector<int> flag(26,1);
        
    	for (auto var = s.begin(); var != s.end(); var++)
        {
    		vec[*var - 'a'] = vec[*var - 'a'] + count;
            count++;
            
            flag[*var - 'a']--;
        }
        for(int i= 0 ; i < vec.size(); i++)
        {
            if(vec[i]!=0 && flag[i]==0)
            {
                if(temp > vec[i])
                {
                    temp = vec[i];
                    index = temp -1;
                }
            }
        }
        
    	return index;
    }
    

    '''


Log in to reply
 

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