We pre-calculate the factorial for 1 to 10 first, then iterate thorught the string and add all the factorial up.
Now we sum then up, and chekc if this sum can be formed by the original numers digits.
Code
class Solution {
public:
bool isDigitorialPermutation(int n) {
vector<int> fac(10, 1);
for(int i = 1 ; i < 10 ; ++i) fac[i] = fac[i-1] * i;
string s = to_string(n);
int cnt = s.size();
int sum = 0;
for(int i = 0 ; i < cnt ; ++i) {
sum += fac[s[i] - '0'];
}
string s2 = to_string(sum);
if(s2.size() != s.size()) return false;
unordered_map<char, int> charCnt;
for(const auto& c: s) ++charCnt[c];
for(const auto& c: s2) {
if(charCnt[c] == 0) return false;
--charCnt[c];
}
return true;
}
};