Anagrams [LeetCode]
Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
Summary: To sort and compare strings, using map to record distinct strings.
class Solution {
public:
vector<string> anagrams(vector<string> &strs) {
vector<string> result;
map<string, int> str_map;
for(int i = ; i < strs.size(); i ++) {
string tmp = strs[i];
std::sort(tmp.begin(), tmp.end());
if(str_map.find(tmp) == str_map.end()) {
str_map[tmp] = i;
}else {
result.push_back(strs[i]);
if(str_map[tmp] >= ) {
result.push_back(strs[str_map[tmp]]);
str_map[tmp] = -;
}
}
}
return result;
}
};
Anagrams [LeetCode]的更多相关文章
- Group Anagrams - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Group Anagrams - LeetCode 注意点 字母都是小写的 解法 解法一:用一个字符串表示strs[i]中出现的字母,比如:abc-> ...
- Anagrams leetcode java
题目: Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will ...
- 49. Group Anagrams - LeetCode
Question 49. Group Anagrams Solution 思路:维护一个map,key是输入数组中的字符串(根据字符排好序) Java实现: public List<List&l ...
- LeetCode 解题报告索引
最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中...... ...
- [LeetCode] Find Anagram Mappings 寻找异构映射
Given two lists A and B, and B is an anagram of A. B is an anagram of A means B is made by randomizi ...
- LeetCode 字符串专题(一)
目录 LeetCode 字符串专题 <c++> \([5]\) Longest Palindromic Substring \([28]\) Implement strStr() [\(4 ...
- Solution to LeetCode Problem Set
Here is my collection of solutions to leetcode problems. Related code can be found in this repo: htt ...
- [LeetCode] Find All Anagrams in a String 找出字符串中所有的变位词
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...
- [LeetCode] Anagrams 错位词
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
随机推荐
- Burpsuite之Http Basic认证爆破
有的时候经常遇到401.今天正好朋友问怎么爆破,也顺便记录一下 怕忘记了 referer:http://www.2cto.com/Article/201303/194449.html 看到Burpsu ...
- 4、Type fundamentals
1.All Types Are Derived from System.Object The CLR requires all objects to be created using the new ...
- iOS 框架收集
检测硬件设备信息 https://github.com/Shmoopi/iOS-System-Services
- git学习笔记11-git多人协作-实际多人怎么开发
当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin. 要查看远程库的信息,用git remote: $ git r ...
- 卷积FFT、NTT、FWT
先简短几句话说说FFT.... 多项式可用系数和点值表示,n个点可确定一个次数小于n的多项式. 多项式乘积为 f(x)*g(x),显然若已知f(x), g(x)的点值,O(n)可求得多项式乘积的点值. ...
- linux学习笔记2-命令总结4
帮助命令 help - 帮助命令 man - 获取帮助信息 用户管理命令 useradd - 添加新用户 passwd - 设置用户密码 who - 显示所有用户 w - 查看更详细的用户信息 use ...
- IO端口、IO内存、IO空间、内存空间的含义和联系
1,IO空间:X86一个特有的空间,与内存空间独立的空间,同样利用IO空间可以操作数据,只不过是利用对应的IO端口操作函数,例如inb(), inbw(), inl(); outb(), outw() ...
- Oracle数据库高级查询(五)集合查询
现实需求有时候需要将多个查询组合到一个查询中去 这时就需要使用集合查询操作了 这个操作类似于数学中的交集,并集,和补集的操作 交集就是返回两个查询共有的记录,关键字是INTERSECT 并集是返回 ...
- Linux GDB Debug
http://blog.jobbole.com/107925/ gdb 调试入门,大牛写的高质量指南 http://blog.jobbole.com/107759/ gdb是the GNU Debug ...
- Oracle一个用户查询另一个用户的表数据
1.两个用户是在不同的库,需要建立dblink 2.属于同一个库的不同用户 1)方法一:使用"用户名."的方式访问 例如:要从USER1账号访问USER2中的表TABLE2 A. ...