1 public class Solution {
 2     public int countNumbersWithUniqueDigits(int n) {
 3         if (n == 0) {
 4             return 1;
 5         }
 6         int result = 10;
 7         int currentD = 9;
 8         int nextD = 9;
 9         
10         while (n-- > 1) {
11             result += currentD * nextD;
12             currentD *= nextD--;
13         }
14         return result;
15     }
16 }

 

1. When n == 0, it return 1.

2. Since already make result = 10, count until 2.

posted on 2016-06-29 14:57  keepshuatishuati  阅读(121)  评论(0编辑  收藏  举报