O(1) C++ Solution


  • 0
    N
    static const int arr[] = {1,10,91,739,5275,32491,168571,712891,2345851,5611771,8877691};
    
    class Solution {
    public:
        int countNumbersWithUniqueDigits(int n) {
           if(n <= 10) return arr[n];
           else return arr[10];
        }
    };
    
    

  • 0
    N
    let arr = tail $ scanl (+)  0 (1 : scanl (*) 9 [9,8..1] ) 
    let getN n = if (n <= 10 ) then (arr !!n ) else (arr!!10)
    
    

Log in to reply
 

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