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& ...
随机推荐
- 配置文件——WebApp.config文件读取和修改
using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using ...
- 使用BlockingQueue的生产者消费者模式
BlockingQueue很好的解决了多线程中,如何高效安全“传输”数据的问题.通过这些高效并且线程安全的队列类,为我们快速搭建高质量的多线程程序带来极大的便利.使用场景. 首先它是一个队列,而一个队 ...
- java web 插件式开发
1.支持pagelet2.菜单扩展3.静态文件访问 4.开发环境. 5.OSGi平台. tms:pagelet 是一个jsp标签 <div> <tms:pagelet show=&q ...
- JAVA 流式布局管理器
//流式布局管理器 import java.awt.*; import javax.swing.*; public class Jiemian2 extends JFrame{ //定义组件 JBut ...
- git fetch和git pull(转载)
From:http://www.tech126.com/git-fetch-pull/ Git中从远程的分支获取最新的版本到本地有这样2个命令: 1. git fetch:相当于是从远程获取最新版本到 ...
- java NIO经典实例
服务端: Loader.java package net.chatroom.server; public class Loader { public static void main(String[] ...
- WebBrowserControl
Before navigating the URL, write meta into webbrowser's documenttext property as follows: //Setting ...
- [ActionScript 3.0] AS3.0 水面波纹效果
import flash.geom.Point; import flash.display.BitmapData; import flash.filters.DisplacementMapFilter ...
- [ActionScript 3.0] AS3 访问舞台上元件的方法
文档类: package { import flash.display.MovieClip; public class Main extends MovieClip { public function ...
- [ActionScript 3.0] AS3 深入理解Flash的安全沙箱Security Domains
简介 如果你还没有与复杂的的安全域(security domain)和应用程序域(application domain)问题打过交道,那么你真是个幸运的家伙.当你在加载外部内容(然后他们开始播放)的时 ...