LeetCode 48 Anagrams
Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
public class Solution {
public List<String> anagrams(String[] strs) {
ArrayList<String> result = new ArrayList<String>();
HashMap<String, String> hm = new HashMap<String, String>();
for (String str : strs) {
char[] c = str.toCharArray();
Arrays.sort(c);
if (!hm.containsKey(String.valueOf(c))) {
hm.put(String.valueOf(c), str);
} else {
String s = hm.get(String.valueOf(c));
if (!result.contains(s))//某个回文序列第一次出现的单词,
//我们并没有加入,如今补上
result.add(s);
result.add(str);
}
}
return result;
}
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
LeetCode 48 Anagrams的更多相关文章
- [array] leetcode - 48. Rotate Image - Medium
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...
- 前端与算法 leetcode 48. 旋转图像
目录 # 前端与算法 leetcode 48. 旋转图像 题目描述 概要 提示 解析 解法一:转置加翻转 解法二:在单次循环中旋转 4 个矩形 算法 传入测试用例的运行结果 执行结果 GitHub仓库 ...
- [LeetCode] Group Anagrams 群组错位词
Given an array of strings, group anagrams together. Example: Input: ["eat", "tea" ...
- [LeetCode] 48. Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- 【leetcode】Anagrams
Anagrams Given an array of strings, return all groups of strings that are anagrams. Note: All inputs ...
- 【leetcode】Anagrams (middle)
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- Java for LeetCode 049 Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- Leetcode#49 Anagrams
原题地址 Anagram:变位词.两个单词是变位词关系的条件是:组成单词的字符相同,只是顺序不同 第一次看这道题看了半天没明白要干嘛,丫就不能给个样例输入输出么..后来还是看网上其他人的总结知道是怎么 ...
- LeetCode 48. Rotate Image(旋转图像)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
随机推荐
- graph driver-device mapper-01driver初始化
// thin device数据结构 type DevInfo struct { Hash string `json:"-"` DeviceId int `json:"d ...
- set、env、export差分
set:显示当前shell变量,用户变量包含当前用户 env:显示用户变量 export:显示当前导出成用户变量的shell变量 举例来说: root@kali:~# aaa=bbb ...
- Windows Phone开发(10):常用控件(上)
原文:Windows Phone开发(10):常用控件(上) Windows Phone的控件有几个来源,和传统的桌面应用程序开发或Web开发一样,有默认提供的控件和第三方开者发布的控件.一般而言,如 ...
- mysql copy复制拷贝表数据及结构的几种方式(转)
mysql拷贝表操作我们会常常用到,下面就为您详细介绍几种mysql拷贝表的方式,希望对您学习mysql拷贝表方面能够有所帮助.假如我们有以下这样一个表:id username password--- ...
- MVC Razor视图引擎控件
0.日期转化
- win7,win8取得管理员权限 .reg文件
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\runas] @="获取管理员所有权" " ...
- minihomepage.exe 百度视频迷你主页
百度视频最近动作可真.延续"DHot.exe 热点资讯"之后,又在桌面上出现了Tips窗体,例如以下图: 尽管是迷你的,可还是把其他桌面图标给挡了啊! 突然出来这么个窗体.我还以为 ...
- 设单链表中存放n个字符,试设计一个算法,使用栈推断该字符串是否中心对称
转载请注明出处:http://blog.csdn.net/u012860063 问题:设单链表中存放n个字符.试设计一个算法,使用栈推断该字符串是否中心对称,如xyzzyx即为中心对称字符串. 代码例 ...
- Linux(Centos)中tcpdump参数用法详解(转)
在linux下进行编程开发的人尤其是网络编程的人会经常需要分析数据包,那么一定会用到tcpdump,下面就是关于tcpdump的使用方法说明(1). tcpdump的选项 -a 将网络地址 ...
- EL字符串表达式和常用功能用途拦截
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> ${wj ...