Package g2501_2600.s2514_count_anagrams
Class Solution
- java.lang.Object
-
- g2501_2600.s2514_count_anagrams.Solution
-
public class Solution extends Object
2514 - Count Anagrams.Hard
You are given a string
s
containing one or more words. Every consecutive pair of words is separated by a single space' '
.A string
t
is an anagram of strings
if theith
word oft
is a permutation of theith
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 modulo109 + 7
.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:
1 <= s.length <= 105
s
consists of lowercase English letters and spaces' '
.- There is single space between consecutive words.
- For example,
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
-
-
Method Detail
-
countAnagrams
public int countAnagrams(String s)
-
-