当前位置:网站首页>leetcode--49字母异位词分组
leetcode--49字母异位词分组
2022-07-16 20:33:00 【Peihj2021】
49字母异位词分组

解题思路
1.将不同的字符串转换为字符数组并按照字母顺序进行排序
2.异位词排序后的结果相同,故可以作为哈希表的key值
3.将字母异位词组成的集合作为哈希表的value值
代码
class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
if (strs == null || strs.length == 0){
return new ArrayList();
}
HashMap<String, List> hashMap = new HashMap<>();
for (String str : strs) {
char[] chars = str.toCharArray();
Arrays.sort(chars);
String s = String.valueOf(chars);
if (!hashMap.containsKey(s)){
hashMap.put(s,new ArrayList());
}
hashMap.get(s).add(str);
}
return new ArrayList(hashMap.values());
}
}
参考
https://leetcode.cn/problems/group-anagrams/solution/zi-mu-yi-wei-fen-zu-ha-xi-biao-zhu-bu-zh-gf9q/
边栏推荐
- Developers share the initial experience of tinyms, a high-level API tool of mindspire!
- MySQL transaction operation and locking mechanism
- PHP memory overflow? How to solve it?
- TCP congestion control details | 6 Active queue management
- How to record sound on win11 screen? Win11 method of recording screen video with sound
- (手工)【sqli-labs58-61】限制注入次数:报错注入、GET注入、字符/数字型
- LINGO运算符和内置函数
- A New Optimizer Using Particle Swarm Theory
- Application of botu PLC Fuzzy PID in liquid level control of double tank (fuzzy and ordinary PID switching function FB)
- The 100 billion yuan universe market is the new driving force of soul and Yingke
猜你喜欢

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

UCOSII里面为什么调用OS_ENTER_CRITICAL()或OS_EXIT_CRITICAL()会出错,出错信息为:undeclared identifier `cpu_sr‘

多租户SaaS的数据库设计模式

A New Optimizer Using Particle Swarm Theory

(手工)【sqli-labs58-61】限制注入次数:报错注入、GET注入、字符/数字型

Graduation season -- common interview questions in database
![How to deal with time series event data? [doctoral thesis of Munich University of technology] neural time series point process (ntpp): continuous time event data modeling](/img/fb/b76b94fa4973123e90743a36788595.png)
How to deal with time series event data? [doctoral thesis of Munich University of technology] neural time series point process (ntpp): continuous time event data modeling

alicloud3搭建wordpress

伺服阀moogD634-374C

Remember once, ants were abused on all sides. The water was too deep. Have you built the ferry across the river?
随机推荐
Deepmind's latest 114 page report "emerging barter trade behavior in Multi-Agent Reinforcement Learning"
Graduation season -- common interview questions in database
解题-->在线OJ(十六)
Developers share | handwriting operator is not so difficult. I'll teach you to use mindspire to realize adaptive average pooling operator!
After reading this article, I will teach you to play with vulnhub, the penetration test target machine -- evilbox one
【大型电商项目开发】缓存-分布式锁-Redisson简洁&整合-lock锁-Redisson解决死锁-读写锁-闭锁-信号量-44
Examen de l'activité | discussion approfondie avec mindstore: comment open source explore l'ensemble du paysage de l'IA
博途PLC模糊PID控制(量化因子和比例因子)
创建型模式之享元模式
私域运营很火,私域运营是否适合所有企业?
Problem solving -- > online OJ (16)
创新中心首发!恭喜佳华物链云获MindSpore认证!
Dior is suspected of plagiarizing Chinese horse face skirt, and the product has been removed from the domestic official website
1、shell-echo > 和 echo>>
[play with es] es batch / full import data
Myql database suddenly disappeared, how to restore it?
The distant savior obeys the objective law (VI) -- cultural attribute
2-conan 二进制包依赖管理方案
Modify server password
[UCOS III source code analysis] - mutually exclusive semaphores (mutually exclusive locks)