Skip to content

Latest commit

 

History

History
76 lines (55 loc) · 1.95 KB

0438-find-all-anagrams-in-a-string.adoc

File metadata and controls

76 lines (55 loc) · 1.95 KB

438. Find All Anagrams in a String

{leetcode}/problems/find-all-anagrams-in-a-string/[LeetCode - Find All Anagrams in a String^]

Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.

Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.

The order of output does not matter.

Example 1:
Input:
s: "cbaebabacd" p: "abc"

Output:
[0, 6]

Explanation:
The substring with start index = 0 is "cba", which is an anagram of "abc".
The substring with start index = 6 is "bac", which is an anagram of "abc".
Example 2:
Input:
s: "abab" p: "ab"

Output:
[0, 1, 2]

Explanation:
The substring with start index = 0 is "ab", which is an anagram of "ab".
The substring with start index = 1 is "ba", which is an anagram of "ab".
The substring with start index = 2 is "ab", which is an anagram of "ab".

解题分析

使用滑动窗口来"圈定"字符串!

一刷
link:{sourcedir}/_0438_FindAllAnagramsInAString.java[role=include]
二刷
link:{sourcedir}/_0438_FindAllAnagramsInAString_2.java[role=include]

思考题

尝试使用数组来代替 Map