一、题目说明 题目是49. Group Anagrams,给定一列字符串,求同源词(包含相同字母的此)的集合。题目难度是Medium。 二、我的做法 题目简单,就不多说,直接上代码: 性能如下: 三、优化措施 主要是用了unordered_map,也用到了sort排序,当然用map也可以。 晕了,不 ...
分类:
其他好文 时间:
2020-02-14 11:02:10
阅读次数:
79
class Solution: def findAnagrams(self, s: str, p: str) List[int]: l=0 r=0 res = [] p_d = {} windows_d = {} for _ in p: p_d[_] = p_d.get(_,0)+1 while(r ...
分类:
其他好文 时间:
2020-02-13 14:38:04
阅读次数:
73
题目大意: 两串字符串 s 和 t 是否 anagrams(下文简称ANA) 的定义是: 是否能将 s 内的字母打乱顺序后再拼接得到 t 我们考虑互相ANA的两串字符串 s 和 t 我们称 t 是 s 的 reducible anagram(下文简称RANA),在当存在一个数 k≥2,且满足下面的定 ...
分类:
其他好文 时间:
2020-02-04 10:30:03
阅读次数:
94
D. Irreducible Anagrams time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let's call two s ...
分类:
其他好文 时间:
2020-02-03 12:19:08
阅读次数:
167
D. Irreducible Anagrams 题意 若两个字符串中每个字符的个数都是一样的,则称他们互为$anagrams$。现在定义两个字符串s,t是$reducible~anagram$的,必须满足下面的条件: 1. 将s、t两个字符串分别拆成k(k =2)个连续子串 2. $s_1,s_2\ ...
分类:
其他好文 时间:
2020-02-03 12:03:02
阅读次数:
61
群组错位词。题意是给一个数组,数组里面的元素是字符串,请将input根据错位词的原则分组输出。例子, Example: Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat"," ...
分类:
其他好文 时间:
2020-01-24 09:12:21
阅读次数:
79
LeetCode 49: 字母异位词分组 Group Anagrams 题目: 给定一个字符串数组,将字母异位词组合在一起。字母异位词指字母相同,但排列不同的字符串。 Given an array of strings, group anagrams together. 示例: 说明: 所有输入均为 ...
分类:
其他好文 时间:
2019-12-07 22:55:38
阅读次数:
84
Given an array of strings, group anagrams together. Example: Note: All inputs will be in lowercase. The order of your output does not matter. 基本的遍历练手题 ...
分类:
其他好文 时间:
2019-10-27 23:15:32
阅读次数:
163
"Group Anagrams" Given an array of strings, group anagrams together. Example: Note: All inputs will be in lowercase. The order of your output does not ...
分类:
其他好文 时间:
2019-10-27 20:18:35
阅读次数:
91