当前位置:网站首页>Leetcode 49. Alphabetic heterotopic word grouping
Leetcode 49. Alphabetic heterotopic word grouping
2022-07-18 22:41:00 【Java full stack R & D Alliance】
Topic delivery :https://leetcode.cn/problems/group-anagrams/
The code is as follows :
class Solution {
public static List<List<String>> groupAnagrams(String[] strs) {
List<List<String>> result = new ArrayList<>();
HashMap<String, List<String>> map = new HashMap<>();
for (String str : strs) {
String[] split = str.split("");
Arrays.sort(split);
if (map.containsKey(Arrays.toString(split))) {
List<String> strings = map.get(Arrays.toString(split));
strings.add(str);
map.put(Arrays.toString(split), strings);
} else {
List<String> strings = new ArrayList<>();
strings.add(str);
map.put(Arrays.toString(split), strings);
}
}
Set<String> keys = map.keySet();
for (String key : keys) {
List<String> strings = map.get(key);
result.add(strings);
}
return result;
}
}
边栏推荐
- Arduino窗口乱码问题
- Product of JS primes in Huawei computer test
- pdf中的超链接,跳转之后,如何返回去? alt + ←
- Examen de l'activité | discussion approfondie avec mindstore: comment open source explore l'ensemble du paysage de l'IA
- Source code analysis of ArrayList
- [UCOS III source code analysis] - time slice rotation
- In addition to Chang'an, these four domestic brands also use "Lexus face". Has Chinese design regressed?
- 【部署】Redis
- Three sides of headlines + four sides of Alibaba + five sides of Tencent took the offer to share the summary, and finally joined Alibaba
- Honghu Wanlian Zhiyuan development board is officially integrated into the openharmony backbone
猜你喜欢

How to solve the problem of 8080 port being occupied? Win11 8080 port occupied solution

Encapsulate and obtain system user information, roles and authority control

Lingo solves the maximum (small) value of piecewise function

看完这篇 教你玩转渗透测试靶机vulnhub——EvilBox-One

Nike, the leader of sports, is "red and black" in the trend of consumption recovery

Open source ten questions, a quick start guide for community newcomers

千亿元宇宙市场,Soul、映客的新动力

Developers share the initial experience of tinyms, a high-level API tool of mindspire!

Topic selection recommendation of the latest information security graduation project

Tencent is all around. It's silly to ask
随机推荐
操作dom逆序,面试题
uCOSIIV2.93移植时为什么会出错,错误信息为undefined symbol ‘_OSTaskReturnHook‘
Voice conversion history research record
LCD 显示撕裂解决
Lingo solves the maximum (small) value of piecewise function
封装、获取系统用户信息、角色及权限控制
transpose函数
How to solve the problem of 8080 port being occupied? Win11 8080 port occupied solution
pdf中的超链接,跳转之后,如何返回去? alt + ←
Win11录屏怎么录声音?Win11录屏幕视频带声音的方法
js 手写sort
npm安装教程
J-dict-select-tag drop-down box failure solution
Encapsulate and obtain system user information, roles and authority control
surging作者出具压测结果
Examen de l'activité | discussion approfondie avec mindstore: comment open source explore l'ensemble du paysage de l'IA
Honghu Wanlian Zhiyuan development board is officially integrated into the openharmony backbone
开发者分享 | MindSpore高阶API工具TinyMS初体验!
The distant savior obeys the objective law (VII) -- cultural attribute
uniapp基础知识