python - HackerRank 上的 SherlockAndAnagrams 算法解释错了吗?

标签 python algorithm dictionary data-structures hashtable

这是一个链接:https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dictionaries-hashmaps

这是我不同意的部分:

在位置 [[[0],[1]],[[0],[2]],[[0],[3]],[[ 1],[2]],[[1],[3]]

和 [[2],[3]] 。

在位置 [[0,1],[1,2]],[[0,1],[2,3]] 和 [[1,2] 处有 3 个 [kk,kk] 形式的变位词],[2,3]] 。

在位置 [[0,1,2],[1,2,3]] 处有 1 个形式为 [kkk,kkk] 的变位词。

我认为解释不正确的原因是:

1- 形式 [kk,kk] 我们有更多的变位词 [[0,1],[0,2]],[[0,1],[0,3]],[[1,2] ,[1,3]]

2- 形式 [kkk,kkk] 我们有更多的变位词 [[0,1,2],[0,2,3]], [[0,1,2],[0,1,3] ] 等等。

是我理解错了还是作者写错了?

请注意,在他上面的解释中,他并没有只按顺序使用字谜,所以我想知道他为什么不使用我找到的字谜?

最佳答案

Two strings are anagrams of each other if the letters of one string can be rearranged to form the other string. Given a string, find the number of pairs of substrings of the string that are anagrams of each other.

您应该仔细阅读链接中给出的字谜定义。作者没有错误。

关于python - HackerRank 上的 SherlockAndAnagrams 算法解释错了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57444379/

相关文章:

algorithm - 不知道限制 sin(x) 公式循环

c - Bresenham 的画线算法

java - 在Java中对多个相对列表进行排序

java - 将两张 map 合并为第三张

python - 无法将数据帧保存到 parquet pyspark

python - 找到素数的概率(使用米勒-拉宾检验)

python - 使用 python json.loads 解析 unicode 输入

algorithm - 矩阵的 Grundy 数

python - 键对于 python 字典来说不是唯一的!

python - Matplotlib制作不重叠气泡图(圆圈堆积)