C++ deque


  • 0
    int firstUniqChar(string s) {
            unordered_map<char,int>m(26);
            deque<int>q;
            for(int i=0;i<s.size();i++){
                if(m[s[i]]==0) q.push_back(i);
                if(m[s[i]]>0&&!q.empty()){
                   if(s[i]==s[q.front()]) q.pop_front();
                   while(!q.empty()&&m[s[q.front()]]>1) q.pop_front();
                }
                m[s[i]]++;
            }
            return q.empty()?-1:q.front();
        }
    

Log in to reply
 

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