use std::collections::HashMap;
impl Solution {
fn group_anagrams(strs: Vec<String>) -> Vec<Vec<String>> {
let mut map: HashMap<String, Vec<String>> = HashMap::new();
for s in strs {
// Clone and sort the characters of the string to form the key
let mut chars: Vec<char> = s.chars().collect();
chars.sort_unstable();
let key = chars.into_iter().collect::<String>();
// Push the original string into the vector corresponding to the sorted key
map.entry(key).or_insert_with(Vec::new).push(s);
}
// Extract the vectors of anagrams and return them
map.into_iter().map(|(_key, value)| value).collect()
}
}