g0301_0400.s0357_count_numbers_with_unique_digits.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java21 Show documentation
Show all versions of leetcode-in-java21 Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
package g0301_0400.s0357_count_numbers_with_unique_digits;
// #Medium #Dynamic_Programming #Math #Backtracking
// #2022_07_11_Time_0_ms_(100.00%)_Space_41.2_MB_(23.67%)
public class Solution {
public int countNumbersWithUniqueDigits(int n) {
int ans = 1;
for (int i = 1; i <= n; i++) {
int mul = 1;
for (int j = 1; j < i; j++) {
mul *= (10 - j);
}
ans = ans + 9 * mul;
}
return ans;
}
}