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 438. Find All Anagrams in a StringLeetCode
- [LeetCode] Group AnagramLeetCode
- (轉)leetcode:Find All Anagrams in a String 滑動視窗方法總結LeetCode
- LeetCode|劍指 Offer 49.醜數LeetCode
- 【leetcode 49】【字母異位詞分組】LeetCode
- Leetcode 25 Reverse Nodes in k-GroupLeetCode
- Leetcode_49_字母異位分組_mapLeetCode
- LeetCode 49. 字母異位詞分組LeetCode
- 【Leetcode】25.Reverse Nodes in k-GroupLeetCode
- [Leetcode力扣 25] Reverse Nodes in k-GroupLeetCode力扣
- Q25 LeetCode49 字母異位詞分組LeetCode
- [LeetCode] 2134. Minimum Swaps to Group All 1s Together IILeetCode
- vue49Vue
- group conv
- group_replication_bootstrap_group 用於什麼boot
- 資料庫的sort group by和hash group by資料庫
- day49-rest框架REST框架
- oracle partition by group by,詳解partition by和group by對比Oracle
- MySQL Group ReplicationMySql
- Group by 優化優化
- 每週分享第 49 期
- sqli-labs————Less-49SQL
- Linq使用Group By 1
- 04-dispatch_group
- SAP Purchasing Group in DetailsAI
- 7.98 GROUP_ID
- group by 查詢原理
- Group by 最佳化
- PostgreSQL DBA(49) - Index(SP-GiST)SQLIndex
- Oracle OCP(49):表空間管理Oracle
- ERP的Account group和CRM partner group的對映關係
- Exchange - Add Owner of Distribution Group
- MySQL group replication介紹MySql
- odoo group by 彙總功能Odoo
- three.js之GroupJS
- MASM中Group的作用ASM
- max() group by共用問題