2514. Count Anagrams Hard
1/**
2 * [2514] Count Anagrams
3 *
4 * You are given a string s containing one or more words. Every consecutive pair of words is separated by a single space ' '.
5 * A string t is an anagram of string s if the i^th word of t is a permutation of the i^th word of s.
6 *
7 * For example, "acb dfe" is an anagram of "abc def", but "def cab" and "adc bef" are not.
8 *
9 * Return the number of distinct anagrams of s. Since the answer may be very large, return it modulo 10^9 + 7.
10 *
11 * <strong class="example">Example 1:
12 *
13 * Input: s = "too hot"
14 * Output: 18
15 * Explanation: Some of the anagrams of the given string are "too hot", "oot hot", "oto toh", "too toh", and "too oht".
16 *
17 * <strong class="example">Example 2:
18 *
19 * Input: s = "aa"
20 * Output: 1
21 * Explanation: There is only one anagram possible for the given string.
22 *
23 * Constraints:
24 *
25 * 1 <= s.length <= 10^5
26 * s consists of lowercase English letters and spaces ' '.
27 * There is single space between consecutive words.
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/count-anagrams/
33// discuss: https://leetcode.com/problems/count-anagrams/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn count_anagrams(s: String) -> i32 {
39 0
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_2514() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.