Difficult:Medium
題目
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:
1 | Input: strs = ["eat","tea","tan","ate","nat","bat"] |
Example 2:
1 | Input: strs = [""] |
Example 3:
1 | Input: strs = ["a"] |
解題思路
1.設長度26內容為0的矩陣
2.字串中有的字母將0改為1
3.檢查map是否有這個群組
Solution
Code 1 :
1 | var groupAnagrams = function(strs) { |