← 返回 snowflake 的题目列表Find All Anagrams in a String
类型:qbank
Given two strings s and p, return an array of all the start indices of p's anagrams in s.
Problem Requirements
You are provided with two strings, s and p. Your task is to find every position in s where an anagram of p begins.
You must return a list of these starting indices. The order of the indices in your result does not matter.
Note: An anagram is a word or phrase made by rearranging the letters of a different word or phrase, using all the original letters exactly once.
Sample Scenarios
Scenario 1
Input: s = "cbaebabacd", p = "abc"
Output: [0,6]
Explanation:
At index 0, the substring is "cba", which is an anagram of "abc".
At index 6, the substring is "bac", which is an anagram of "abc".
Scenario 2
Input: s = "abab", p = "ab"
Output: [0,1,2]
Explanation:
At index 0, "ab" is an anagram.
At index 1, "ba" is an anagram.
At index 2, "ab" is an anagram.
Technical Limitations
The length of both strings s and p is between 1 and 30,000 (3 * 10^4).
Both s and p are made up of only lowercase English letters.