leetcode 49. Group Anagrams
2016-03-15 21:34
435 查看
Given an array of strings, group anagrams together.
For example, given:
Return:
Note:
For the return value, each inner list's elements must follow the lexicographic order.
All inputs will be in lower-case.
accepted
For example, given:
["eat", "tea", "tan", "ate", "nat", "bat"],
Return:
[ ["ate", "eat","tea"], ["nat","tan"], ["bat"] ]
Note:
For the return value, each inner list's elements must follow the lexicographic order.
All inputs will be in lower-case.
class Solution { public: vector<vector<string>> groupAnagrams(vector<string>& strs) { map<map<char, int>, set<string>>gr; map<string, int>strscount; for (int i = 0; i < strs.size(); i++) { string s = strs[i]; map<char, int>count; strscount[s]++; for (int j = 0; j < s.length(); j++) count[s[j]]++; gr[count].insert(strs[i]); } vector<vector<string>>re; for (map<map<char, int>, set<string>>::iterator it = gr.begin(); it != gr.end(); it++) { vector<string>ss; for (set<string> ::iterator it1 = it->second.begin(); it1 != it->second.end(); it1++) { for (int i = 0; i < strscount[*it1]; i++) ss.push_back(*it1); } re.push_back(ss); } return re; } };
accepted
相关文章推荐
- Hadoop集群启动常见异常
- python常见面试问题
- 一个和圆内接多边形有关的命题
- 02.启动流程
- 【初步了解什么是面向对象编程】
- Python设计模式(10)-模板模式
- 89. Gray Code
- 153. Find Minimum in Rotated Sorted Array
- linux第12天 线程
- python图片转字符
- NamedManager安装Web管理bind9的DNS服务器
- Android入门简介
- Java多态中重载方法参数分别为父类和子类时的疑惑
- poj3253--pat---优先队列---堆
- 01.磁盘管理
- 关于css的简介?
- 62. Unique Paths
- Andriod——手机尺寸相关的概念 +尺寸单位+关于颜色
- source insigt、pc-lint、VS联合使用
- 从 AngularJS 模块定义说起