Maybe Best Solution | Test Case Incorrect?!


  • -1
    S

    There are only 10 digits. When n >= 10 the return value will not change. So there are only 10 possible results.

    DP is not clever enough. Just pre-calculate and cache.

    public class Solution {
        static int[] cache = new int[]{10, 91, 739, 5275, 32491, 168571, 712891, 2345851, 5611771, 8877691};
    	
    	public int countNumbersWithUniqueDigits(int n) {
    	    if (n == 0) return 1;
    		else if (n > 10) return cache[9];
    		
    		return cache[n - 1];
    	}
    }
    

  • 0
    D

    0 ≤ x < 10^0=1 => x=0 => return 1


  • 0
    S

    @dingty Oh you are right. Thanks!


Log in to reply
 

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