Question: Given an array of strings strs, group the anagrams together. You can return the answer in any order.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Example 1:
Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Code:
class Solution
{
public:
vector<vector<string>> groupAnagrams(vector<string> &strs)
{
unordered_map <unordered_multiset <char>, vector<string>> mp1;
for (c : strs)
{
unordered_multiset<char> ms1;
for (char h : c)
m1.insert(h);
mp1[ms1].push_back(c);
}
vector<vector<string>> res;
for (auto c : mp1)
res.push_back(c.second);
return res;
}
};
Error:
Line 6: Char 67: error: call to implicitly-deleted default constructor of 'unordered_map<unordered_multiset<char>, vector<std::string>>' (aka 'unordered_map<unordered_multiset<char>, vector<basic_string<char>>>')
unordered_map <unordered_multiset <char>, vector<string>> mp1;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unordered_map.h:141:7: note: explicitly defaulted function was implicitly deleted here
unordered_map() = default;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unordered_map.h:105:18: note: default constructor of 'unordered_map<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>, std::hash<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>, std::equal_to<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>, std::allocator<std::pair<const std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>>>>' is implicitly deleted because field '_M_h' has a deleted default constructor
_Hashtable _M_h;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/hashtable.h:414:7: note: explicitly defaulted function was implicitly deleted here
_Hashtable() = default;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/hashtable.h:174:7: note: default constructor of '_Hashtable<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::pair<const std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>>, std::allocator<std::pair<const std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>>>, std::__detail::_Select1st, std::equal_to<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>, std::hash<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true>>' is implicitly deleted because base class '__detail::_Hashtable_base<unordered_multiset<char, hash<char>, equal_to<char>, allocator<char>>, pair<const unordered_multiset<char, hash<char>, equal_to<char>, allocator<char>>, vector<basic_string<char>, allocator<basic_string<char>>>>, _Select1st, equal_to<unordered_multiset<char, hash<char>, equal_to<char>, allocator<char>>>, hash<unordered_multiset<char, hash<char>, equal_to<char>, allocator<char>>>, _Mod_range_hashing, _Default_ranged_hash, _Hashtable_traits<true, false, true>>' has a deleted default constructor
: public __detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal,
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/hashtable_policy.h:1822:5: note: explicitly defaulted function was implicitly deleted here
_Hashtable_base() = default;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/hashtable_policy.h:1771:5: note: default constructor of '_Hashtable_base<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::pair<const std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>>, std::__detail::_Select1st, std::equal_to<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>, std::hash<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, false, true>>' is implicitly deleted because base class '_Hash_code_base<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::pair<const std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>>, std::__detail::_Select1st, std::hash<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, _Hashtable_traits<true, false, true>::__hash_cached::value>' has a deleted default constructor
: public _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/hashtable_policy.h:1373:7: note: explicitly defaulted function was implicitly deleted here
_Hash_code_base() = default;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/hashtable_policy.h:1349:7: note: default constructor of '_Hash_code_base<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::pair<const std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>, std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>>, std::__detail::_Select1st, std::hash<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>' is implicitly deleted because base class '_Hashtable_ebo_helper<1, std::hash<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>>' has a deleted default constructor
private _Hashtable_ebo_helper<1, _H1>,
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/hashtable_policy.h:1096:7: note: explicitly defaulted function was implicitly deleted here
_Hashtable_ebo_helper() = default;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/hashtable_policy.h:1094:7: note: default constructor of '_Hashtable_ebo_helper<1, std::hash<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>, true>' is implicitly deleted because base class 'std::hash<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>' has a deleted default constructor
: private _Tp
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/functional_hash.h:101:19: note: default constructor of 'hash<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>' is implicitly deleted because base class '__hash_enum<std::unordered_multiset<char, std::hash<char>, std::equal_to<char>, std::allocator<char>>>' has no default constructor
struct hash : __hash_enum<_Tp>
^
Aucun commentaire:
Enregistrer un commentaire