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& ...
随机推荐
- (C#) 调用执行批处理文件
Task: 在Windows的Service里面定时的调用执行一个批处理文件. private ApplicationOutput RunCommandOnPC(string executableP ...
- 深入分析ConcurrentHashMap(转)
线程不安全的HashMap 因为多线程环境下,使用HashMap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap,如以下代码 final HashMap ...
- JAVA 数组实例-求学生平均成绩,与计算数组的长度
实例: 知识点:数组名.length是计算数组的长度 import java.util.*; //求学生平均分成绩 public class Test{ public static void main ...
- get/close not same thread Druid 连接池一个设置
我就郁闷了,1000W+数据审核每次总是到一半就出这么个错,仔细找找原来是一个配置项的小问题,removeAbandonedTimeout 这个代表你从连接池取出一个连接多少秒之后你还没还回来,那就强 ...
- java多线程之生存者与消费者(Java编程思想)
1.通过wait() 与 Notify实现 package Produce; import java.util.concurrent.ExecutorService; import java.util ...
- angularjs 与django标签语法冲突的解决办法
在需要使用angularjs标签的地方套上verbatim标签,如: {% verbatim %} ... {% endverbatim %}
- [HDU 3689]Infinite monkey theorem (KMP+概率DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3689 黄老师说得对,题目只有做wa了才会有收获,才会有提高. 题意:一个猴子敲键盘,键盘上有n个键,猴 ...
- Isilon OneFS Simulator Install Guide
Isilon build for storage data Use VMware converter to convert node1 to ESX(参考silon_OneFS_Simulator_I ...
- POJ 3308 Paratroopers(最小割EK(邻接表&矩阵))
Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the ...
- 推荐一个PHP在线代码运行的网站
地址:http://www.manongjc.com/runcode 该网站可以运行php代码.html代码.js代码, 对于初学者来说,免去了安装环境这一步.