2018年7月18日 星期三

[Notes] Precalculated Values

Example: [Leetcode] 357. Count Numbers with Unique Digits: https://leetcode.com/problems/count-numbers-with-unique-digits/description/


Statement: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10^n.

class Solution {
    private int[] precalculated = new int[] { 
        1, 10, 91, 739, 5275, 32491, 168571, 712891, 2345851, 5611771, 8877691
    };

    public int countNumbersWithUniqueDigits(int n) {
        return precalculated[Math.min(n, 10)];
    }
}

沒有留言:

張貼留言