//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的更多相关文章

  1. LeetCode - 49. Group Anagrams

    49. Group Anagrams Problem's Link ------------------------------------------------------------------ ...

  2. Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  3. 【Leetcode】【Medium】Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  4. 49. Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  5. LeetCode49 Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  6. leetcode@ [49] Group Anagrams (Hashtable)

    https://leetcode.com/problems/anagrams/ Given an array of strings, group anagrams together. For exam ...

  7. 【LeetCode】49. Group Anagrams

    题目: Given an array of strings, group anagrams together. For example, given: ["eat", " ...

  8. 【一天一道LeetCode】#49. Group Anagrams

    一天一道LeetCode系列 (一)题目 Given an array of strings, group anagrams together. For example, given: [" ...

  9. Group Anagrams 群组错位词

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

随机推荐

  1. (MVVM) button enable 时,UI没有被刷新。

    if (!this.CanExecuteSubmitButton) { this.CanExecuteSubmitButton = true; CommandManager.InvalidateReq ...

  2. Eclipse - JDK内存配置- 环境配置

    ==================Eclipse环境配置=============================JDK : -Xms32m -Xmx800m backgroundColor: 85 ...

  3. XAMPP Error: Apache shutdown unexpectedly. 解决思路

    我建议首先 运行在cmd中运行 (安装目录)apache/bin/httpd.exe 之后就很好确定错误的具体原因了,而不是根据下面的那样猜端口,比如我遇到的问题,就是配置的路径不存在导致的. 参考资 ...

  4. PLSQL_数据泵导入导出数据Impdp/ Expdp(概念)

    2014-08-31 Created By BaoXinjian

  5. CSS根据屏幕分辨率应用相应样式

    当屏幕尺寸小于1200px时,应用下面的CSS样式 @media screen and (max-width: 1200px) { /*当屏幕尺寸小于1200px时,应用下面的CSS样式*/ .ind ...

  6. android xml操作

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.ArrayList; import ...

  7. jquery 源码剖析1

    ()();   闭包,让声明的变量变成局部变量,使外部无法访问,防止和其他代码冲突,互不影响. (function(){ })();              和一般执行方法一样的. jQuery=f ...

  8. python 最长公共子序列

    网上有很多,但有bug,特别是这个:http://www.oschina.net/code/snippet_16840_2015 好大的坑... get length def lcs_len(a,b) ...

  9. 使用bs4对海投网内容信息进行提取并存入mongodb数据库

    example:    http://xyzp.haitou.cc/article/722427.html 首先是直接下载好每个页面,可以使用 os.system( "wget " ...

  10. springmvc 对REST风格的支持

    1.PathVariable注解 用于映射url的占位符到目标方法的参数中 例子: @RequestMapping("/testPathVariable/{id}") public ...