A C# solution. Feedback welcome!


  • 0
    V
    public class Solution {
        public int CountNumbersWithUniqueDigits(int n) {
                if (n == 0) return 1;
                
                // We begin with 9, instead of 10
                // to skip all numbers that are not n digits
                int fact = 9;
                for (int i = 1; i < n; i++)
                {
                    fact *= (10 - i);
                }
    
                return fact + CountNumbersWithUniqueDigits(n-1);
    
        }
    }
    

Log in to reply
 

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