题目要求: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. Amdocs收购OPENET:关于5G应用落地的思考

    今年8月,全球通讯和媒体领导者之一Amdocs收购了Openet.在VoltDB,听到这个消息,我们感到非常高兴和自豪!在过去的7年里,我们一直是Openet解决方案的基础数据平台. 尽管许多供应商仍 ...

  2. ZOJ 1005 Jugs(BFS)

    Jugs In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with th ...

  3. Java 解决Enum.valueOf找不到枚举出现的异常

    由于Enum.valueOf匹配不到枚举时会出现异常,这个可以用try...catch来解决,但是这样会导致代码往臃肿的道路上越走越远. 本文与其说是解决Enum.valueOf找不到枚举出现的异常还 ...

  4. leetcode146 longest-substring-without-repeating-character

    题目描述 给定一个字符串,找出最长的不具有重复字符的子串的长度.例如,"abcabcbb"不具有重复字符的最长子串是"abc",长度为3.对于"bbb ...

  5. Pycharm激活码,2020年9月29日最新激活码

    分享一个Pycharm激活码给大家: 5MJ8MJ2T1Q-eyJsaWNlbnNlSWQiOiI1TUo4TUoyVDFRIiwibGljZW5zZWVOYW1lIjoi6I635Y+W77yaIG ...

  6. 关于目标检测(Object Detection)的文献整理

    本文对CV中目标检测子方向的研究,整理了如下的相关笔记(持续更新中): 1. Cascade R-CNN: Delving into High Quality Object Detection 年份: ...

  7. Vue3.0响应式原理

    Vue3.0的响应式基于Proxy实现.具体代码如下: 1 let targetMap = new WeakMap() 2 let effectStack = [] //存储副作用 3 4 const ...

  8. spring中的事务有两种方式

    1种是我们常用的声明式事务,如注解,或者配置文件配置的. 2种是编程式事务,如 TransactionTemplate 类的使用.

  9. API简介(二)

    API简介(二) API简介(一)一文中,介绍了使用API的目的.设计.发行政策以及公共API的含义,本篇主要介绍API的用法,从库和框架.操作系统.远程API.Web API四个方面展开. 库和框架 ...

  10. SQL SERVER数据库内 FOR XML PATH 函数用法

    把自己点点滴滴的学习记录下来!!!! 一.FOR XML PATH 简单介绍 那么还是首先来介绍一下FOR XML PATH ,假设现在有一张兴趣爱好表(TBJTXXCE)用来存放就诊患者信息,表结构 ...