当前位置:网站首页>Leetcode 49. 字母异位词分组
Leetcode 49. 字母异位词分组
2022-07-16 13:44:00 【Java全栈研发大联盟】
题目传送:https://leetcode.cn/problems/group-anagrams/
代码如下:
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;
}
}
边栏推荐
- 程序分析与优化 - 11 多分支分析
- Xray安装使用
- 达梦数据库表SQL语句
- Web crawler crawls the inspirational bullet screen of station B and generates word cloud (careful note summary)
- Today's sleep quality record 85 points
- 串的概念相关及模式匹配
- 一次有趣(想打断同事腿)的键盘BUG调试经历
- 监督学习week 3: Logistic Regression optional_lab收获记录
- Thread.sleep简介说明
- [基础服务] [数据库] MySQL 主从复制部署与配置
猜你喜欢

定了,6大领域93个开源任务,阿里开源导师带你参与中科院开源之夏2022

ctf-pikachu-sql

Touche pussy cat

Resolved SQL_ ERROR_ INFO: “You have an error in your SQL syntax; check the manual that corresponds to your

IDEA安装、配置、测试

Unity游戏文件大,如何缩小游戏文件

2022 simulated 100 questions and simulated examination for the main principals of hazardous chemical business units

阿里妈妈展示广告引擎新探索:迈向全局最优算力分配

C#网络应用编程,异步编程基础练习

JD finance, are you bad, or are you cutting too much??
随机推荐
Instance Noise A trick for stabilising GAN training
Export data with navicatpremium
2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
2022 simulated 100 questions and simulated examination for the main principals of hazardous chemical business units
Image xmage de Huawei: Cherchez toutes les images du monde et voyez enfin Bodhisattva
输入一个url全过程详解
The simple solution the boss wants vs. the needs the programmer understands | cartoon
阿里妈妈展示广告引擎新探索:迈向全局最优算力分配
100% accuracy, Alibaba business travel billing system architecture design practice
26个顶级开源项目,87个开放任务,阿里巴巴编程之夏2022学生报名通道开启
2022 P gas cylinder filling examination questions and simulation examination
Digital pyramid (PTA)
Use plt When the savefig() method saves the drawing, the picture is all white or all black
NoSQLAttack工具下载与使用
This article takes you to graph transformers
代码注释的艺术,优秀代码真的不需要注释吗?
程序分析与优化 - 11 多分支分析
随心玩玩(八)jenkins学习(待更新)
ctf-pikachu-RCE
10个第一、2个第二,达摩院NLP团队在SemEval 2022的夺冠之旅