Steward
分享是一種喜悅、更是一種幸福
程式語言 - LeetCode - CPP - 357. Count Numbers with Unique Digits
參考資訊:
https://www.cnblogs.com/grandyang/p/5582633.html
題目:

方法:
1位數:10種 2位數:9 * 9 = 81種 3位數:9 * 9 * 8 = 648種
解答:
class Solution {
public:
int countNumbersWithUniqueDigits(int n) {
if (n == 0) {
return 1;
}
int ans = 10;
int cnt = 9;
for (int i = 2; i <= n; ++i) {
cnt *= (11 - i);
ans += cnt;
}
return ans;
}
};