Class Solution
-
- All Implemented Interfaces:
public final class Solution2514 - Count Anagrams\.
Hard
You are given a string
scontaining one or more words. Every consecutive pair of words is separated by a single space' '.A string
tis an anagram of stringsif the <code>i<sup>th</sup></code> word oftis a permutation of the <code>i<sup>th</sup></code> word ofs.For example,
"acb dfe"is an anagram of"abc def", but"def cab"and"adc bef"are not.
Return the number of distinct anagrams of
s. Since the answer may be very large, return it modulo <code>10<sup>9</sup> + 7</code>.Example 1:
Input: s = "too hot"
Output: 18
Explanation: Some of the anagrams of the given string are "too hot", "oot hot", "oto toh", "too toh", and "too oht".
Example 2:
Input: s = "aa"
Output: 1
Explanation: There is only one anagram possible for the given string.
Constraints:
<code>1 <= s.length <= 10<sup>5</sup></code>
sconsists of lowercase English letters and spaces' '.There is single space between consecutive words.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegercountAnagrams(String s)-
-
Method Detail
-
countAnagrams
final Integer countAnagrams(String s)
-
-
-
-