G2A Many GEOs
SHARE
TWEET

Group Anagrams

a guest Apr 8th, 2020 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     vector<vector<string>> groupAnagrams(vector<string>& strs) {
  4.         map<string, vector<string>> mp;
  5.         map<string, vector<string>>::iterator it;
  6.         vector<vector<string>> result;
  7.        
  8.         for(int i = 0; i < strs.size(); i++){
  9.             string tmp = strs[i];
  10.             sort(strs[i].begin(), strs[i].end());
  11.             mp[strs[i]].push_back(tmp);
  12.         }
  13.        
  14.         for(it = mp.begin(); it != mp.end(); it++)
  15.             result.push_back(it->second);
  16.        
  17.         return result;
  18.     }
  19. };
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top