Anagrams
2015-07-11 01:28
232 查看
Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
Solution:
Note: All inputs will be in lower-case.
Solution:
class Solution { public: vector<string> anagrams(vector<string>& strs) { vector<string> res; unordered_map<string, int> um; for(int i = 0; i < strs.size(); ++i) { string str = strs[i]; sort(str.begin(), str.end()); if(um.count(str) == 0) um[str] = i; else { if(um[str] >= 0) { res.push_back(strs[um[str]]); um[str] = -1; } res.push_back(strs[i]); } } return res; } };
相关文章推荐
- 删除文件及文件夹
- log4j 日志配置 -- properties 和 xml两种形式
- 一个led-platfrom设备驱动的例子
- 学习CocoaPods的使用心得
- ubuntu software center install button gray
- C小加 之 随机数
- windows安装java/jdk
- 整数的二进制表示中有多少个1的问题
- Leetcode23-Merge k Sorted Lists
- linux分区和文件系统
- 同位语
- shell编程技术之-基础知识
- 各种递归算法化简(化复杂)的方法和案例
- UVA 111 History Grading(最长公共子序列dp)
- centos 7 启动tomcat服务
- POJ 2762 tarjan缩点+并查集+度数
- Ecmascript-262-3 in detail. Chapter 4. Scope chain.
- servlet
- display:none与visible:hidden的区别
- 黑马程序员-IOS学习笔记 C语言编程时常犯十八个错误