All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0301_0400.s0357_count_numbers_with_unique_digits.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g0301_0400.s0357_count_numbers_with_unique_digits

// #Medium #Dynamic_Programming #Math #Backtracking
// #2022_11_19_Time_104_ms_(100.00%)_Space_32.7_MB_(100.00%)

class Solution {
    fun countNumbersWithUniqueDigits(n: Int): Int {
        if (n == 0) return 1
        var temp = 9
        var res = 10
        for (i in 1 until n) {
            temp *= (10 - i)
            res += temp
        }
        return res
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy