438. Find All Anagrams in a String Medium

@problem@discussion
#Hash Table#String#Sliding Window



1/**
2 * [438] Find All Anagrams in a String
3 *
4 * Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.
5 * An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
6 *  
7 * Example 1:
8 * 
9 * Input: s = "cbaebabacd", p = "abc"
10 * Output: [0,6]
11 * Explanation:
12 * The substring with start index = 0 is "cba", which is an anagram of "abc".
13 * The substring with start index = 6 is "bac", which is an anagram of "abc".
14 * 
15 * Example 2:
16 * 
17 * Input: s = "abab", p = "ab"
18 * Output: [0,1,2]
19 * Explanation:
20 * The substring with start index = 0 is "ab", which is an anagram of "ab".
21 * The substring with start index = 1 is "ba", which is an anagram of "ab".
22 * The substring with start index = 2 is "ab", which is an anagram of "ab".
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= s.length, p.length <= 3 * 10^4
28 * 	s and p consist of lowercase English letters.
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/find-all-anagrams-in-a-string/
34// discuss: https://leetcode.com/problems/find-all-anagrams-in-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn find_anagrams(s: String, p: String) -> Vec<i32> {
40        vec![]
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_438() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.