[C++] Permutation with explaination
\nclass Solution {\npublic:\n    int permutation(int m, int n) {\n        // m number with len n\n        // m * (m - 1) * (m - 2) .. * (m - n + 1) \n        in
```\nclass Solution {\npublic:\n    int permutation(int m, int n) {\n        // m number with len n\n        // m * (m - 1) * (m - 2) .. * (m - n + 1) \n        int res = 1;\n        while (n) {\n            res *= m;\n            m--;\n            n--;\n        }\n        return res;\n    }\n    int numDupDigitsAtMostN(int n) {\n        vector<int> digits; // to store each digit\n        for (int x = n + 1; x > 0; x /= 10) {\n            digits.push_back(x % 10);\n        }\n        // make it from high to low\n        // e.g., n=137 => [7, 1, 3] => [1, 3, 7]\n        reverse(digits.begin(), digits.end());\n        \n        // get the # of digits\n        int size = digits.size();\n        \n        // to count the number without duplicates\n        int res = 0;\n        \n        // one digit to (size - 1) digits\n        // e.g, n=8759 (4 digits), ignore leading 8 here\n        // so the last 3 digits have 9 * (9 * 8) permutations\n        // the last 2 digits have 9 * (9) permutations\n        // the last 1 digits have 9 permutations\n        for (int i = 1; i < size; i++) {\n            res += 9 * permutation(9, i - 1);\n        }\n        \n        // consider the leading digit\n        unordered_set<int> st; // to store the leading fixed one\n        // for each digit\n        for (int i = 0; i < size; i++) {\n            // i = 0 (first digit) e.g., n=8759 | the free will be\n            // 1xxx, 2xxx, ..., 7xxx\n            // i > 0 e.g., n=8759 | the free will be\n            // 80xx, 81xx, ...86xx\n            for (int j = i > 0 ? 0 : 1; j < digits[i];j++) {\n                // the current digit should not duplicated with the fixed one\n                if (st.find(j) != st.end()) continue;\n                res += permutation(9 - i, size - i - 1);\n            }\n            // if the current leading digit duplicate with previous ones => break\n            if (st.find(digits[i]) != st.end()) break;\n            // insert the current leading digit to the hash table\n            st.insert(digits[i]);\n        }\n        return n - res;\n    }\n};\n```
['C']