题目简单,关键是灵茶山艾府的代码写起来太优美,不得不记录一下
const int Mod = 1e9+7;
using ll = long long;
ll qmi(ll a,ll b,ll mod){ll res =1;while(b){if(b&1)res = res*a%mod;a=a*a%mod;b>>=1;}return res;
}class Solution {
public:int countAnagrams(string s) {int cnt[30]{};int j = 0;long long ans = 1ll,mul=1ll;for(int i=0;i<s.size();i++){if(s[i]==' '){memset(cnt,0,sizeof cnt);j = 0;}else{mul = mul*++cnt[s[i]-'a']%Mod;ans = ans*++j%Mod;}}return ans*qmi(mul,Mod-2,Mod)%Mod;}
};