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

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])

 public class Solution {
public int countNumbersWithUniqueDigits(int n) { if (n < ) return ;
if (n == ) return ; // 0 - 10
int count = countNumbersWithUniqueDigits(n - ); // 1 到 n-1 位数。
int result = ; // there are 9 choices in the first number. 9 in the second number, 8 in the third, 7 in the fourth number.......
for (int i = ; i < n - ; i++) { // n位数
result = result * ( - i);
}
return count + result;
}
}

Count Numbers with Unique Digits的更多相关文章

  1. LC 357. Count Numbers with Unique Digits

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

  2. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

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

  3. Leetcode: Count Numbers with Unique Digits

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

  4. 357. Count Numbers with Unique Digits

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

  5. 【Leetcode】357. Count Numbers with Unique Digits

    题目描述: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. ...

  6. [Swift]LeetCode357. 计算各个位数不同的数字个数 | Count Numbers with Unique Digits

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

  7. Java [Leetcode 357]Count Numbers with Unique Digits

    题目描述: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. ...

  8. Count Numbers with Unique Digits -- LeetCode

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

  9. 【LeetCode】357. Count Numbers with Unique Digits 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

随机推荐

  1. inline-block 和 float 的区别

    1.float元素会自动成为一个块元素. 2.float元素,会脱离文档流!   默认脱离文档流的元素的z-index值是比没有脱离文档流的元素高的! 3.float:没有上下哦,  上下用margi ...

  2. ansible-1 的安装

    该文章摘自:http://my.oschina.net/firxiao/blog/343395,该文章制作笔记使用,不做他用,转载请注明原文链接出处 Ansible 默认是基于SSH协议进行通信的. ...

  3. Oracle单组函数

    --Upper  -------把字符转换成大写       SELECT Upper ('abcde') FROM dual ; --Lower   ----- 把字符转换成小写      SELE ...

  4. 【poj2891】 Strange Way to Express Integers

    http://poj.org/problem?id=2891 (题目链接) 题意 求解线性同余方程组,不保证模数一定两两互质. Solotion 一般模线性方程组的求解,详情请见:中国剩余定理 细节 ...

  5. 活用scanf

    scanf()是C语言中用于读入格式化数据(formatted data)的函数. 我们可能对scanf()的一般用法已经了然,而至于scanf()读入数据的机制恐怕并不十分清楚. 下面我将比较详细地 ...

  6. 多线程java代码移植到android&下载文本界面的更新

    1)效果演示:

  7. 使用Tengine替代Nginx作为负载均衡服务器

    Tengine是由淘宝网发起的Web服务器项目.它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性.Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检 ...

  8. ON THE EVOLUTION OF MACHINE LEARNING: FROM LINEAR MODELS TO NEURAL NETWORKS

    ON THE EVOLUTION OF MACHINE LEARNING: FROM LINEAR MODELS TO NEURAL NETWORKS We recently interviewed ...

  9. 修改php执行用户,并使其拥有root权限

    useradd apachephp vi /etc/httpd/conf/httpd.conf 将组和用户修改成apachephp,重启apache,然后用lsof -i:80查看apache的执行用 ...

  10. 新浪微博客户端(24)-计算原创微博配图frame

    DJStatus.h #import <Foundation/Foundation.h> @class DJUser; /** 微博 */ @interface DJStatus : NS ...