My_code


  • 0
    Y

    class Solution {
    public:

    vector<vector<string>> groupAnagrams(vector<string>& strs) {
      map<string,int>ma;
      vector<vector<string>>result;
        for(auto x:strs){
           string tmp=x;
           sort(tmp.begin(),tmp.end());
            if(ma.find(tmp)!=ma.end())
                result[ma[tmp]].push_back(x);
            else
            {
                int i=result.size();
                ma[tmp]=i;
                vector<string>tmp2;
                tmp2.push_back(x);
                result.push_back(tmp2);
            }
            
        }
        return result;
        
    }
    

    };


Log in to reply
 

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