C++ DP solution


  • 0
    X
    class Solution {
    public:
        int countNumbersWithUniqueDigits(int n) {
            if(n > 10){
                n = 10;
            }
            if(n == 0){
                return 1;
            }else if(n == 1){
                return 10;
            }
            int num = 10;
            for(int k = 2; k <= n; ++k){
                int tmp = 9;
                for(int i = 9; i >= 11 - k; --i){
                    tmp *= i;
                }
                num += tmp;
            }
            return num;
        }
    };

  • 0
    G
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.