4 lines c++ solution


  • 0
    M
    int countNumbersWithUniqueDigits(int n) {
        int ans = 10, tmp = 9;
        for(int i = 1; i < n && tmp; ++i)
            ans += (tmp *= (10-i));
        return (n == 0)?1:ans;
    }
    

Log in to reply
 

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