Table-Driven Methods from "Code Complete 2", all O(1), Golang Solution


  • 0

    results are only 11 different number. Make them a table.

    func countNumbersWithUniqueDigits(n int) int {
    	res := []int{1, 10, 91, 739, 5275, 32491, 168571, 712891, 2345851, 5611771, 8877691}
    	if n >= 10 {
    		return res[10]
    	}
    
    	return res[n]
    }
    

Log in to reply
 

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