//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. 25 个超棒的 HTML5 & JavaScript 游戏引擎开发库

    就像在汽车中,引擎完成主要的工作,使汽车看起来不可思议.游戏引擎同理,游戏开发者完成细节的工作,使游戏看起来真实.吸引人眼球.游戏引擎负责其余的事情.早期,游戏开发者通常从草图做起,花费高昂,且不容易 ...

  2. 分页写入文件,第二次分页前一定要关闭IO流啊。。否则文件写不全。。- -粗心

  3. PLSQL_查询SQL的执行次数和频率(案例)

    2014-12-25 Created By BaoXinjian

  4. php之面向对象、构造函数、析构函数

    <!DOCTYPE HTML> <html> <head> <title></title> <meta charset="u ...

  5. git(4)如何在windows上安装git

    windows版本git(1.9.2)下载:点击下载 下完之后点击双击安装: 我安装的是默认的目录:一路next,最后就安装完成了,中间步骤中也有unix下安装的选项: 我的安装目录是在:C:\Pro ...

  6. 8 个 Git 的小技巧

    git 已经成为了我日常必备工具之一,我总结我几乎每天使用的8个有用(且简洁)的git技巧.   使用-p选择性添加 当你想提交内容时,你可以通过使用 git commit -am 来选择所有文件或使 ...

  7. C开源hash项目uthash

    uthash 是C的比较优秀的开源代码,它实现了常见的hash操作函数,例如查找.插入.删除等.该套开源代码采用宏的方式实现hash函数的相关功能,支持C语言的任意数据结构最为key值,甚至可以采用多 ...

  8. 最大公约数Greatest Common Divisor(GCD)

    一 暴力枚举法 原理:试图寻找一个合适的整数i,看看这个整数能否被两个整形参数numberA和numberB同时整除.这个整数i从2开始循环累加,一直累加到numberA和numberB中较小参数的一 ...

  9. flask test_client设置cookies

    class TestCase(unittest.TestCase): session = None def setUp(self): self.app = create_app() self.app. ...

  10. Spring配置项<context:annotation-config/>说明

    配置applicationContext.xml时经常会看到: <context:annotation-config/> 它的作用是隐式地向Spring容器注册AutowiredAnnot ...