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. zoj3890 BFS

    就是搜. #include<stdio.h> #include<string.h> #include<queue> using namespace std; #de ...

  2. ztree设置节点checked

    1.根据id获取树的某个节点: var zTree = $.fn.zTree.getZTreeObj("mytree"); var node = zTree.getNodeByPa ...

  3. iOS开发icon&images Size

    https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix ...

  4. Dinic问题

    问题:As more and more computers are equipped with dual core CPU, SetagLilb, the Chief Technology Offic ...

  5. BZOJ-2929 洞穴攀岩 最大流Dinic(傻逼题)

    竟然没有1A真羞耻...1分钟不到读完题,10分钟不到打完....MD没仔细看...WA了一遍,贱! 2929: [Poi1999]洞穴攀行 Time Limit: 1 Sec Memory Limi ...

  6. Java多线程基础(一)

    一.基本概念 线程状态图包括五种状态 1.新建状态(New):线程对象被创建后,就进入新建状态.例如,Thread thread=new Thread(); 2.就绪状态(Runnable):也被称为 ...

  7. photon mapping阶段性总结

    PM算法看了这么久,也该是到了总结的时候了.自己实现的是PPPM(Probabilistic progressive photon mapping)的一个简化形式.之所以是简化形式是由于我的光子搜集时 ...

  8. [asp.net mvc]自定义filter

    写在前面 最近在摸索mvc,在app中的webview中嵌入h5应用,经常需要用到对cookie的读取操作.所以想到通过自定义的filter截取cookie,然后通过在action上面打特性的方式针对 ...

  9. Oracle 11g客户端在Linux系统上的配置步骤详解

    Oracle 11g客户端在Linux系统上的配置步骤详解 2011-07-26 10:47 newhappy2008 CSDN博客 字号:T | T 本文我们主要介绍了Oracle 11g客户端在L ...

  10. tyvj1213 嵌套矩形

    描述    有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a<c,b<d或者b<c,a<d(相当于旋转X90度).例如 ...