leetcode_357. Count Numbers with Unique Digits

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

给定一个n,计算[0,10^n]中十进制中每一位都不相同的数的数目。

 

class Solution{
public:
    int countNumbersWithUniqueDigits(int n){
        int res=0;
        int wei = min(10, n);
        for(int i=wei; i>0; i--){
            int tmp = 9;
            for(int j=i-1; j>0; j--)
                tmp *= 9-i+j+1;
            res+=tmp;
        }
        return res+1;
    }
};

 

posted on 2019-03-23 20:29  JASONlee3  阅读(104)  评论(0编辑  收藏  举报

导航