题目要求:Anagrams

Given an array of strings, return all groups of strings that are anagrams.

Note: All inputs will be in lower-case.

分析:

参考网址:http://www.cnblogs.com/easonliu/p/3643595.html

代码如下:

class Solution {
public:
vector<string> anagrams(vector<string> &strs) { string s;
map<string, int> anagram;
vector<string> res; for (int i = 0; i < strs.size(); ++i) {
s = strs[i];
sort(s.begin(), s.end());
if (anagram.find(s) == anagram.end()) {
anagram[s] = i;
} else {
if (anagram[s] >= 0) {
res.push_back(strs[anagram[s]]);
anagram[s] = -1;
}
res.push_back(strs[i]);
}
}
return res;
}
};

LeetCode 049 Anagrams的更多相关文章

  1. Java for LeetCode 049 Anagrams

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  2. [LeetCode] Group Anagrams 群组错位词

    Given an array of strings, group anagrams together. Example: Input: ["eat", "tea" ...

  3. 【leetcode】Anagrams

    Anagrams Given an array of strings, return all groups of strings that are anagrams. Note: All inputs ...

  4. 【leetcode】Anagrams (middle)

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  5. Leetcode#49 Anagrams

    原题地址 Anagram:变位词.两个单词是变位词关系的条件是:组成单词的字符相同,只是顺序不同 第一次看这道题看了半天没明白要干嘛,丫就不能给个样例输入输出么..后来还是看网上其他人的总结知道是怎么 ...

  6. LeetCode 48 Anagrams

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  7. [LeetCode 题解]: Anagrams

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  8. Leetcode 之Anagrams(35)

    回文构词法,将字母顺序打乱.可将字母重新排序,若它们相等,则属于同一组anagrams. 可通过hashmap来做,将排序后的字母作为key.注意后面取hashmap值时的做法. vector< ...

  9. careercup-排序和查找 11.2

    11.2 编写一个方法,对字符串数组进行排序,将所有变位词1排在相邻的位置. 类似leetcode:Anagrams 解法: 变位词:由变换某个词或短语的字母顺序构成的新的词或短语.例如,“trian ...

随机推荐

  1. python框架Django中MTV之Model(数据模型)

    MTV框架之Model(数据模型) 关注公众号"轻松学编程"了解更多. 1.连接MySQL数据库 项目中的settings.py设置范例 # 配置数据库 DATABASES = { ...

  2. 【CF1443F】Identify the Operations 题解

    原题链接 题意简介 建议去原题看.这题意我表达不清楚. 大概就是给你一个 n 的排列,现在要求你进行 m 次操作. 每次操作,你会在现有的排列中删去一个数,然后选择其左边或右边的一个与之相邻的数加入 ...

  3. 配置交换机Trunk接口流量本地优先转发(集群/堆叠)

    组网图形 Eth-Trunk接口流量本地优先转发简介 在设备集群/堆叠情况下,为了保证流量的可靠传输,流量的出接口设置为Eth-Trunk接口.那么Eth-Trunk接口中必定存在跨框成员口.当集群/ ...

  4. 【Mycat】作为Mycat核心开发者,怎能不来一波Mycat系列文章?

    写在前面 Mycat是基于阿里开源的Cobar产品而研发,Cobar的稳定性.可靠性.优秀的架构和性能以及众多成熟的使用案例使得Mycat一开始就拥有一个很好的起点,站在巨人的肩膀上,我们能看到更远. ...

  5. Canvas鼠标点击特效(富强、民主...)、收藏

    <script> /* 鼠标特效 */ var a_idx = 0; jQuery(document).ready(function($) { $("body").cl ...

  6. div 内元素的垂直居中

    小主今天偷点懒利用上班时间整理一下 div 内元素的居中(不论垂直还是水平通用)问题的解决方法: 本文的中心是利用 css 中的 display属性:通常的方便的是使用 Flex/Grid 属性,今天 ...

  7. 经典分治问题,平面N个点求最近点对

    大家好,我们今天来看一道非常非常经典的算法题--最近点对问题. 这个问题经常在各种面试当中出现,难度不低,很少有人能答上来.说实话,我也被问过,因为毫无准备,所以也没有答上来.是的,这道题有点神奇,没 ...

  8. 1. 线性DP 53. 最大子序和.

    53. 最大子序和. https://leetcode-cn.com/problems/maximum-subarray/ func maxSubArray(nums []int) int { dp ...

  9. Docker安装Oracle11g

    为什么使用docker安装oracle,因为自己搭建配置的话可能时间太久太繁琐等等原因,也因为docker实在太方便了 本文主要是使用docker-compose安装Oracle 11g,因为使用do ...

  10. mds/journal.cc: 2929: FAILED assert解决

    前言 在处理一个其他双活MDS无法启动环境的时候,查看mds的日志看到了这个错误mds/journal.cc: 2929: FAILED assert(mds->sessionmap.get_v ...