Leetcode 49 Group Anagrams
Given an array of strings, group anagrams together.
Example:
Input: ["eat", "tea", "tan", "ate", "nat", "bat"]
,
Output:
[
["ate","eat","tea"],
["nat","tan"],
["bat"]
]
Note:
- All inputs will be in lowercase.
- The order of your output does not matter.
這個題的意思是給出一串字串,然後給出相同字元的一串。
class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
if(strs == null && strs.length == 0){
return new ArrayList<List<String>>();
}
HashMap<String,List<String>> map = new HashMap<>();//設定一個map來做
for(String s : strs){
char[] ss = s.toCharArray();
Arrays.sort(ss);//排序後含有相同的字元的就可以放入list中
String a = String.valueOf(ss);
if(!map.containsKey(a)){
map.put(a,new ArrayList<String>());
}//首先建立
map.get(a).add(s);//map做對映
}
return new ArrayList<List<String>>(map.values());//將map的values中的數進行返回
}
}
相關文章
- LeetCode 49. Group AnagramsLeetCode
- Leetcode AnagramsLeetCode
- Leetcode-AnagramsLeetCode
- Anagrams leetcode javaLeetCodeJava
- LeetCode 438. Find All Anagrams in a StringLeetCode
- [LeetCode] Group AnagramLeetCode
- (轉)leetcode:Find All Anagrams in a String 滑動視窗方法總結LeetCode
- 【leetcode 49】【字母異位詞分組】LeetCode
- LeetCode|劍指 Offer 49.醜數LeetCode
- LeetCode-Group Shifted StringsLeetCode
- Leetcode Reverse Nodes in k-GroupLeetCode
- Leetcode_49_字母異位分組_mapLeetCode
- LeetCode 49. 字母異位詞分組LeetCode
- Leetcode 25 Reverse Nodes in k-GroupLeetCode
- Leetcode-Reverse Nodes in k-GroupLeetCode
- Reverse Nodes in k-Group leetcode javaLeetCodeJava
- 【Leetcode】25.Reverse Nodes in k-GroupLeetCode
- [Leetcode力扣 25] Reverse Nodes in k-GroupLeetCode力扣
- Q25 LeetCode49 字母異位詞分組LeetCode
- vue49Vue
- [LeetCode] 2134. Minimum Swaps to Group All 1s Together IILeetCode
- [CareerCup] 11.2 Sort Anagrams Array 異位詞陣列排序陣列排序
- day49-rest框架REST框架
- C++學習(49)C++
- Oracle GroupOracle
- [LeetCode] Reverse Nodes in k-Group 每k個一組翻轉連結串列LeetCode
- group_replication_bootstrap_group 用於什麼boot
- 資料庫的sort group by和hash group by資料庫
- 每週分享第 49 期
- Viewing Password File Members (49)View
- oracle partition by group by,詳解partition by和group by對比Oracle
- MySQL Group ReplicationMySql
- Group by 優化優化
- Oracle Hash Group ByOracle
- sql用法——group bySQL
- Oracle group by使用Oracle
- ORA-00937: not a single-group group functionFunction
- Oracle OCP(49):表空間管理Oracle