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). ...
随机推荐
- iOS 获取高速随机路径sandbox目录
NSLog(@"%@", NSHomeDirectory());//沙盒主目录 NSLog(@"%@", NSTemporaryDirectory());//砂 ...
- hdu4734(数位dp)
hdu4734 给定 a和b, 问区间[0,b]内有多少个数字的f(i) <=f(a) dp[i][s] 表示i位的数字的f<=s 所以比如如果第i+1位选择数字5之后, 那么只要剩下的i ...
- Android如何获得手机power_profile.xml文件
上的能量消耗进行最近的测试,阅读文章一个月,最后,我们发现了一些新的想法,但产生的问题.那 工作无法再进行下去. 在Android手机中,对于手机中的每一个部件(cpu.led.gps.3g等等)执行 ...
- 深入了解mysql它BDB系列(1)---BDB基础知识
深入了解mysql它BDB系列(1) ---BDB关基础知识 作者:杨万富 一:BDB体系结构 1.1.BDB体系结构 BDB总体的体系结构如图1.1所看到的.包括五个子系统(见图1.1中 ...
- Jetty安装学习并展示
Jetty 的基本架构 Jetty 眼下的是一个比較被看好的 Servlet 引擎,它的架构比較简单,也是一个可扩展性和很灵活的应用server,它有一个基本数据模型,这个数据模型就是 Handler ...
- FPGA开机状态
最近调试FPGA电路时发现一个问题,我从来没有注意过.我们都知道Xilinx的FPGA有三种功率M引脚,这是为了让我们配置三个引脚FPGA装载机模式,什么是主要的字符串.从字符串.并行等.,该手册有. ...
- 解决android3.0版本号以上应用接收不到开机广播问题
如今是2014-07-16 下午15:27. 好久没写过东西,突然间灵感喷发想写点东西(事实上是刚刚弄好了一个棘手的问题,自豪中..呵呵呵呵 我牛掰).废话不多说,进入正题. 不知道你们又没有碰到这问 ...
- 键盘控制div上下左右移动 (转)
<html> <head> <title></title> <link rel="stylesheet" type=" ...
- android对app代码混淆
接到新任务.现有项目的代码混淆.在此之前混淆了一些理解,但还不够具体和全面,我知道有些东西混起来相当棘手. 但幸运的是,现在这个项目是不是太复杂(对于这有些混乱).提前完成--这是总结. 第一部分 介 ...
- 三种方式上传文件-Java
前言:负责,因为该项目他(jetty嵌入式开始SpringMvc)实现文件上传的必要性,并拥有java文件上传这一块还没有被曝光.并 Http 更多晦涩协议.因此,这种渐进的方式来学习和实践上载文件的 ...