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 ...
随机推荐
- hdu 5167(dfs)
Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- Android xmlpull 方式解析xml文件
1.新建一个xml文件,放在res/xml目录下 <?xml version="1.0" encoding="utf-8"?> <citys& ...
- java 获取当前系统时间
Java的Date获取时间函数都是deprecated 可以使用: https://stackoverflow.com/questions/5175728/how-to-get-the-current ...
- Python 进阶 之 enumerate()函数
enumerate()是Python的内置函数,无需依赖包,enumerate()作用是可以将生成器包装成生成器,类似于range,但enumerate()可以自动生成索引. enumerate(pa ...
- thinkphp函数学习(0)——开篇
因为新公司都使用thinkphp,所以就想通读一遍源码,可是在读的过程中,时常半路杀出个自定义函数,然后又要跳到函数定义的地方先看具体的函数定义,感觉特别的难受,好几次都是看到runtime.php就 ...
- IActionResult
- FZU 2150 Fire Game 【两点BFS】
Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns) ...
- 【KM】POJ2195/HDU1533-Going home
//最近没什么时间quq据说长得帅的人都在切八中,然而长得丑的人只能水水裸题 [题目大意] 给出一张地图及人和房屋的位置,求出每个人回到不同房屋所具有的最小代价和. [思路] 最小权匹配,先O(n^2 ...
- Mybatis添加&&删除&&更新
mapper <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC & ...
- Spring.NET的IoC容器(The IoC container)——简介(Introduction)
简介 这个章节介绍了Spring Framework的控制反转(Inversion of Control ,IoC)的实现原理. Spring.Core 程序集是Spring.NET的 IoC 容器实 ...