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. 【BZOJ 1001】狼抓兔子 对偶图+SPFA

    这道题是求图的最小割,也就是用最大流.但因为边太多,最大流算法会T,因此不能用最大流算法. 因为这是个平面图,所以求平面图的最小割可以使用特殊的技巧就是求对偶图然后求对偶图的最短路.把每个面看成一个点 ...

  2. bzoj 1458 网络流

    我们可以知道每行最多可以有多少个格子不用建点,设为x[i],每列同理设为y[i],那么我们连接(source,i,x[i]),(i,sink,y[i])表示我们将一个格子不建点,那么(i,j,flag ...

  3. hihocoder1187 Divisors

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...

  4. iOS应用支持IPV6

    一.IPV6-Only支持是啥? 首先IPV6,是对IPV4地址空间的扩充.目前当我们用iOS设备连接上Wifi.4G.3G等网络时,设备被分配的地址均是IPV4地址,但是随着运营商和企业逐渐部署IP ...

  5. 浅谈IOC--说清楚IOC是什么

    http://www.cnblogs.com/DebugLZQ/archive/2013/06/05/3107957.html 博文目录 1.IOC的理论背景 2.什么是IOC 3.IOC也叫依赖注入 ...

  6. SSH整合之spring整合hibernate

    SSH整合要导入的jar包: MySQL中创建数据库 create database ssh_db; ssh_db 一.spring整合hibernate带有配置文件hibernate.cfg.xml ...

  7. iOS欢迎界面Launch Screen动态加载广告

    有许多应用程序在打开的时候,欢迎界面会加载一张连网获取的广告图片或者显示一组动画,这样的效果是如何做到的呢?下面给大家介绍一种简单的实现加载广告的方式. 程序运行起来,欢迎界面之后,会进入AppDel ...

  8. SSL协议运行机制

    SSL/TLS协议运行机制 一.作用 不使用SSL/TLS的HTTP通信,就是不加密的通信.所有信息明文传播,带来了三大风险. (1) 窃听风险(eavesdropping):第三方可以获知通信内容. ...

  9. object-c(oc)内存管理机制详解

    1.内存的创建和释放 让我们以Object-c世界中最最简单的申请内存方式展开,谈谈关于一个对象的生命周期.首先创建一个对象: 1 2 3 //“ClassName”是任何你想写的类名,比如NSStr ...

  10. 新浪微博客户端(20)-集成MJRefresh

    HomeViewController.m /** 集成下拉刷新控件 */ - (void)setupPullToRefreshView { __unsafe_unretained UITableVie ...