Участник:UlitinAleksander/count-numbers-with-unique-digits

Материал из DISCOPAL
Перейти к: навигация, поиск

Java

https://leetcode.com/problems/count-numbers-with-unique-digits/

class Solution {
    public int countNumbersWithUniqueDigits(int n) {
 
        int[] dp = new int[n+1];
        dp[0] = 1;
        int product  = 9;
        for(int i = 1;i <=n;i++){
            dp[i] = product+dp[i-1];
            product = product*(10-i);
        }
        return dp[n];
    }
}