My Java Solution in O(0) With Help Of Dp Instant


  • 0
    B
      public int countNumbersWithUniqueDigits(int n) {
            if (n==0) return 1;
            n = Math.min(n, 10);
            int dp = 10;
            int sum = 9;
            int pos = 9;
            for (int i = 2; i <=n; i++) {
                sum = sum * pos--;
                dp= dp+sum;
            }
            return dp;
        }
    

Log in to reply
 

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