LeetCode——Anagrams
Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
原题链接:https://oj.leetcode.com/problems/anagrams/
易位构词游戏的英文词汇是 anagram,这个词来源于有“反向”或“再次”的含义的希腊语字根ana-和有“书写”、“写下”的意思的词根grahpein。易位构词是一类 title=%E6%96%87%E5%AD%97%E6%B8%B8%E6%88%8F&action=edit&redlink=1" class="new" title="文字游戏(页面不存在)" style="text-decoration:none; color:rgb(165,88,88); font-family:sans-serif; font-size:14px; line-height:22.399999618530273px">文字游戏
http://zh.wikipedia.org/wiki/%E6%98%93%E4%BD%8D%E6%9E%84%E8%AF%8D%E6%B8%B8%E6%88%8F
public List<String> anagrams(String[] strs) {
List<String> list = new ArrayList<String>();
Map<String,List<String>> map = new HashMap<String,List<String>>();
for(String str : strs){
char[] ch = str.toCharArray();
Arrays.sort(ch);
String s = new String(ch);
if(map.containsKey(s))
map.get(s).add(str);
else{
List<String> li = new ArrayList<String>();
li.add(str);
map.put(s,li);
}
}
for(List<String> ls : map.values()){
if(ls.size() > 1)
list.addAll(ls);
}
return list;
}
LeetCode——Anagrams的更多相关文章
- [LeetCode] Anagrams 错位词
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- leetcode — anagrams
import java.util.*; /** * * Source : https://oj.leetcode.com/problems/anagrams/ * * Created by lverp ...
- [leetcode]Anagrams @ Python
原题地址:https://oj.leetcode.com/problems/anagrams/ 题意: Given an array of strings, return all groups of ...
- Leetcode: Anagrams(颠倒字母而成的字)
题目 Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will ...
- Leetcode Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- LeetCode ---Anagrams() 详解
Notice: Given an array of strings, return all groups of strings that are anagrams. Note: All inputs ...
- LeetCode Anagrams My solution
Anagrams Given an array of strings, return all groups of strings that are anagrams. Note: All inputs ...
- LeetCode: Anagrams 解题报告
AnagramsGiven an array of strings, return all groups of strings that are anagrams. Note: All inputs ...
- [Leetcode] Anagrams 颠倒字母构成词
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
随机推荐
- poj 2826(好坑,线段相交问题)
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11576 Accepted: 176 ...
- poj 2242(已知三点求外接圆周长)
The Circumference of the Circle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8310 ...
- typescript 定义全局变量以及扩展原生js对象
使用“declare global”操作即可. 项目根目录下新建myDeclareFile.d.ts declare global { interface Navigator { mediaSessi ...
- Bot Framework测试
在开发完成Bot Framework后,在本机的模拟器都是成功的,但未知在发布后会出现什么样的问题,所以需要将本机发布的站点给到Bot 1.在Bot Framework注册一个Bot,打开Bot Fr ...
- [xampp] /usr/bin/env: php: No such file or directory
ln -s /opt/lampp/bin/php /usr/local/bin/php
- POJ 2438 Children's Dining(哈密顿回路)
题目链接:http://poj.org/problem?id=2438 本文链接:http://www.cnblogs.com/Ash-ly/p/5452615.html 题意: 有2*N个小朋友要坐 ...
- MySQL密码不能登陆问题
由于种种原因,在进行开发的时候我一直是基于Windows平台,并且以前初学的时候常常重装不同版本的 MySQL数据库.因此长时间不使用后就产生了一些冲突的问题. 简单描述下,今天用以前 ...
- ASP.NET Core 2.2 基础知识(五) 环境
一.环境变量 系统启动时,会读取环境变量 ASPNETCORE_ENVIRONMENT ,并将该变量的值存储在 IHostingEnvironment.EnvironmentName 字段中.如: 新 ...
- [BZOJ 1499] 瑰丽华尔兹
Link:https://www.lydsy.com/JudgeOnline/problem.php?id=1499 Solution : 能立即发现这是和动态规划相关的题目 令f[t][i][j]表 ...
- 【分块】【常数优化】【Orz faebdc】洛谷 P1083 NOIP2012提高组 借教室
分块90分. By AutSky_JadeK [重点在下面] #include<cstdio> #include<cmath> using namespace std; #de ...