All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0301_0400.s0357_count_numbers_with_unique_digits.Solution Maven / Gradle / Ivy

There is a newer version: 1.37
Show newest version
package g0301_0400.s0357_count_numbers_with_unique_digits;

// #Medium #Dynamic_Programming #Math #Backtracking

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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy