Java recrusive Solution


  • 0
    P
    public class Solution {
        public int countNumbersWithUniqueDigits(int n) {
            if(n == 0)
            {
                return 1;
            }
            if(n == 1)
            {
                return 10;
            }
            if(n>10)
            {
                return countNumbersWithUniqueDigits(10);
            }
            int suming = 1;
            for(int i = 0;i<n-1;i++)
            {
                suming *= 9-i;
            }
            suming *= 9;
            return suming + countNumbersWithUniqueDigits(n-1);
        }
    }
    

Log in to reply
 

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