C++ solution using vector


  • 0
    A

    class Solution {
    public:
    int firstUniqChar(string s) {

        int i;
        vector<char> v(s.begin(),s.end());
            for(i=0;i<v.size();i++)
            {
                char tmp=v[i];
                v.erase(v.begin()+i);
                if(find(v.begin(),v.end(),tmp)==v.end())
                    return i;
                v.insert(v.begin()+i,tmp); 
                
            }
        return -1;
    }
    

    };


Log in to reply
 

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