Lintcode(4)-乱序字符串
来源:互联网 发布:mac上删除应用程序 编辑:程序博客网 时间:2024/05/12 15:42
Q:
给出一个字符串数组S,找到其中所有的乱序字符串(Anagram)。如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中。
对于字符串数组 [“lint”,”intl”,”inlt”,”code”]
返回 [“lint”,”inlt”,”intl”]
A:
class Solution {public: /** * @param strs: A list of strings * @return: A list of strings */ vector<string> anagrams(vector<string> &strs) { if (strs.empty()) { return strs; } typedef unsigned int uint32; typedef std::set<int> index_set; typedef std::map<std::string, index_set > index_map; uint32 si = strs.size(); index_map stats; std::vector<std::string> result; for ( uint32 i = 0; i < si; ++i ) { std::string temp(strs[i].begin(), strs[i].end()); std::sort(temp.begin(), temp.end()); stats[temp].insert(i); } for ( index_map::const_iterator it = stats.begin(); it != stats.end(); ++it ) { const index_set& t = it->second; if (t.size() > 1) { for ( index_set::const_iterator it2 = t.begin(); it2 != t.end(); ++it2 ) { result.push_back(strs[*it2]); } } } return result; }};
0 0
- Lintcode(4)-乱序字符串
- LintCode-乱序字符串
- LintCode 乱序字符串
- LintCode:乱序字符串
- lintcode,乱序字符串
- lintcode--乱序字符串
- 乱序字符串-LintCode
- lintcode-乱序字符串-171
- LintCode(M) 乱序字符串
- LintCode 171 乱序字符串
- Lintcode乱序字符串(时间过长)
- 乱序字符串
- 题目:乱序字符串
- 乱序字符串
- 乱序字符串
- (171)乱序字符串
- 乱序字符串_LintCode
- 乱序字符串
- 【Tools】【版本控制管理】Git
- Python正则表达式操作指南
- 汉诺塔问题(递归)
- Android 拼图游戏知识点小结
- shell使用总结(不断补充中...)
- Lintcode(4)-乱序字符串
- 深入理解JavaIO流
- 2015数据泄露调查报告
- 用css制作带三角矩形
- Spring2.5 访问 Session 属性的四种策略
- Masonry介绍与使用实践(快速上手Autolayout)
- 前端面试学习笔记之HTML
- linux安装、配置php、phpmyadmin、oracle-java7
- 树上点分治学习记录