Leetcode049. Group Anagrams
//hashmap implement with STL
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
// sort(strs.begin(),strs.end()); //sort all the element
map<string,vector<string>>hashmap;
for(vector<string>::iterator it=strs.begin();it!=strs.end();it++)
{
string str=*it;
sort(str.begin(),str.end());
hashmap[str].push_back(*it); //hashmap;
}
vector<vector<string>>re;
for(map<string,vector<string>>::iterator it=hashmap.begin();it!=hashmap.end();it++) //each group with the same key
re.push_back(it->second);
return re;
}
};
Leetcode049. Group Anagrams的更多相关文章
- LeetCode - 49. Group Anagrams
49. Group Anagrams Problem's Link ------------------------------------------------------------------ ...
- Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- 【Leetcode】【Medium】Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- 49. Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- LeetCode49 Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- leetcode@ [49] Group Anagrams (Hashtable)
https://leetcode.com/problems/anagrams/ Given an array of strings, group anagrams together. For exam ...
- 【LeetCode】49. Group Anagrams
题目: Given an array of strings, group anagrams together. For example, given: ["eat", " ...
- 【一天一道LeetCode】#49. Group Anagrams
一天一道LeetCode系列 (一)题目 Given an array of strings, group anagrams together. For example, given: [" ...
- Group Anagrams 群组错位词
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
随机推荐
- (MVVM) button enable 时,UI没有被刷新。
if (!this.CanExecuteSubmitButton) { this.CanExecuteSubmitButton = true; CommandManager.InvalidateReq ...
- Eclipse - JDK内存配置- 环境配置
==================Eclipse环境配置=============================JDK : -Xms32m -Xmx800m backgroundColor: 85 ...
- XAMPP Error: Apache shutdown unexpectedly. 解决思路
我建议首先 运行在cmd中运行 (安装目录)apache/bin/httpd.exe 之后就很好确定错误的具体原因了,而不是根据下面的那样猜端口,比如我遇到的问题,就是配置的路径不存在导致的. 参考资 ...
- PLSQL_数据泵导入导出数据Impdp/ Expdp(概念)
2014-08-31 Created By BaoXinjian
- CSS根据屏幕分辨率应用相应样式
当屏幕尺寸小于1200px时,应用下面的CSS样式 @media screen and (max-width: 1200px) { /*当屏幕尺寸小于1200px时,应用下面的CSS样式*/ .ind ...
- android xml操作
import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.ArrayList; import ...
- jquery 源码剖析1
()(); 闭包,让声明的变量变成局部变量,使外部无法访问,防止和其他代码冲突,互不影响. (function(){ })(); 和一般执行方法一样的. jQuery=f ...
- python 最长公共子序列
网上有很多,但有bug,特别是这个:http://www.oschina.net/code/snippet_16840_2015 好大的坑... get length def lcs_len(a,b) ...
- 使用bs4对海投网内容信息进行提取并存入mongodb数据库
example: http://xyzp.haitou.cc/article/722427.html 首先是直接下载好每个页面,可以使用 os.system( "wget " ...
- springmvc 对REST风格的支持
1.PathVariable注解 用于映射url的占位符到目标方法的参数中 例子: @RequestMapping("/testPathVariable/{id}") public ...