Cpp short but slow


  • 0
    P
    #define REP(i,s,n) for(int i=s;i<n;i++)
    #define RIT(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
    class Solution {
    public:
        vector<vector<string>> groupAnagrams(vector<string>& strs) {
            vector<vector<string>> out;
            int n = strs.size();
            map< map<char,int>, multiset<string> > mp;
            for(string s:strs){
                map<char, int> tmp;
                for(char c:s) tmp[c]++;
                mp[tmp].insert(s);
            }
            RIT(it,mp){
                out.push_back(vector<string>(it->second.begin(),it->second.end()));
            }
            return out;
        }
    };

Log in to reply
 

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