LeetCode 49: Anagrams
来源:互联网 发布:三星n9008刷4g网络 编辑:程序博客网 时间:2024/05/21 21:35
Difficulty: 3
Frequency: 4
Problem:
Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
Solution:
class Solution {public: vector<string> anagrams(vector<string> &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function vector <string> answer; if (strs.size()<=1) return answer; map <string, int> anas; for (int i = 0; i<strs.size(); i++) { string s = strs[i]; sort(s.begin(), s.end()); if (anas.find(s)==anas.end()) { anas[s] = i; } else { if (anas[s]>=0) { answer.push_back(strs[anas[s]]); anas[s] = -1; } answer.push_back(strs[i]); } } return answer; }};
Notes:
This not my code. It is AnnieKim's code. Thank her very much for publishing her code.
- Leetcode 49 Anagrams
- LeetCode 49: Anagrams
- [Leetcode 49, medium] Anagrams
- [leetcode 49] Anagrams
- [leetcode 49] Anagrams
- leetcode || 49、Anagrams
- Leetcode 49 Anagrams
- 【leetcode-49】Anagrams(java)
- Leetcode #49 Anagrams
- LeetCode(49) Anagrams
- leetcode 49: Anagrams
- Leetcode#49||Group Anagrams
- leetcode 49:Group Anagrams
- Leetcode 49: Group Anagrams
- 【leetcode】【49】Group Anagrams
- LeetCode 49 - Group Anagrams
- LeetCode 49 Group Anagrams
- leetcode(49):Group Anagrams
- 基准测试工具之tpcc-mysql
- struts1配置
- POJ 2828 线段树 水题
- SurfaceView(2D游戏基础)
- (())、let、expr、bc等计算命令的使用语法和应用技巧
- LeetCode 49: Anagrams
- fedora16 TFTP服务器的安装与配置
- JSTL核心标签库的使用方法和示例
- System Error Codes(GetLastError )0-----5999
- Goautodial 电话流程
- hdu 4406 GPA(费用流)
- 占空比为50%的奇数分频器的设计
- jQuery formValidator插件inputValidator,compareValida
- System Error Codes(GetLastError )6000-----15999