标签:
Example:
Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99]
)
Hint:
public class Solution { public int countNumbersWithUniqueDigits(int n) { //f(1) = 10; //f(2) = f(1) + 9*9; //f(3) = f(2) + 9*9*8; //...... if(n == 0) return 1; if(n == 1) return 10; int ret = 10; int current = 1; while(current<n && current<10) { int part2 = 9; for(int i=0;i<current;++i) { part2 *= 9-i; } ret += part2; ++current; } return ret; } }
357. Count Numbers with Unique Digits
标签:
原文地址:http://www.cnblogs.com/neweracoding/p/5599977.html