一、题目描述

给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n 。

示例:

输入: 2
输出: 91
解释: 答案应为除去 11,22,33,44,55,66,77,88,99 外,在 [0,100) 区间内的所有数字。

二、题目解析

排列组合。第一位有9种,第二位有9种,....第10位有1种,大于10位肯定有重复,返回0

三、代码实现

class Solution {
public:
int countNumbersWithUniqueDigits(int n) {
if (!n)return ;
if (n > )return ;
int res = , tmp = ;
for (int i = ; i < n; ++i) {
tmp *= ( - i);
res += tmp;
}
return res;
}
};

[Leetcode] 第357题 计算各个位数不同的数字个数的更多相关文章

  1. Leetcode 357.计算各个位数不同的数字个数

    计算各个位数不同的数字个数 给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n . 示例: 输入: 2 输出: 91 解释: 答案应为除去 11,22,33 ...

  2. Java实现 LeetCode 357 计算各个位数不同的数字个数

    357. 计算各个位数不同的数字个数 给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n . 示例: 输入: 2 输出: 91 解释: 答案应为除去 11, ...

  3. leetcode 357. 计算各个位数不同的数字个数(DFS,回溯,数学)

    题目链接 357. 计算各个位数不同的数字个数 题意: 给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n . 示例: 输入: 2 输出: 91 解释: 答 ...

  4. 357 Count Numbers with Unique Digits 计算各个位数不同的数字个数

    给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n.示例:给定 n = 2,返回 91.(答案应该是除[11,22,33,44,55,66,77,88,99 ...

  5. [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 ...

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

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

  7. 【LeetCode每天一题】Palindrome Number( 回文数字)

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...

  8. 【JavaScript】【KMP】Leetcode每日一题-实现strStr()

    [JavaScript]Leetcode每日一题-实现strStr() [题目描述] 实现 strStr() 函数. 给你两个字符串 haystack 和 needle ,请你在 haystack 字 ...

  9. leetcode 第188题,我的解法,Best Time to Buy and Sell Stock IV

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

随机推荐

  1. Python-demo(video)

    #!/usr/bin/env python# #-*-coding:utf-8-*-import requestsimport randomimport timedef get_json(url): ...

  2. 安装tomcat出现的问题

    今天在安装tomcat时出现了配置环境不对的问题. 在正确配置Tomcat环境变量后,遇到很多次运行startup.bat后,一个窗口一闪而过的. 解决方法: 1.在tomcat的目录下选中start ...

  3. nanopi NEO2 学习笔记 3:python 安装 RPi.GPIO

    如果我要用python控制NEO2的各种引脚,i2c 或 spi ,RPi.GPIO模块是个非常好的选择 这个第三方模块是来自树莓派的,好像友善之臂的工程师稍作修改移植到了NEO2上,就放在 /roo ...

  4. Java基础之Iterable与Iterator

    Java基础之Iterable与Iterator 一.前言: Iterable :故名思议,实现了这个接口的集合对象支持迭代,是可迭代的.able结尾的表示 能...样,可以做.... Iterato ...

  5. Go 面试每天一篇(第 1 天)

    下面这段代码输出的内容 package main import ( "fmt" ) func main() { defer_call() } func defer_call() { ...

  6. JVM体系结构详解

    每个Java开发人员都知道字节码将由JRE (Java运行时环境)执行.但是很多人不知道JRE是Java Virtual Machine(JVM)的实现,它分析字节码.解释代码并执行代码.作为开发者, ...

  7. Linux下手动安装MySQL5.7

    1.下载tar包,这里使用wget从官网下载 https://dev.mysql.com/downloads/mysql/ 2.将mysql安装到/usr/local/mysql下 # 解压 tar ...

  8. SCRUM的五个事件

    转自:http://www.scrumcn.com/agile/scrum-knowledge-library/scrum.html#tab-id-7 Scrum 使用固定的事件来产生规律性,以此来减 ...

  9. hdu 5903 Square Distance(dp)

    Problem Description A string is called a square string if it can be obtained by concatenating two co ...

  10. codeforces 509 D. Restoring Numbers(数学+构造)

    题目链接:http://codeforces.com/problemset/problem/509/D 题意:题目给出公式w[i][j]= (a[i] + b[j])% k; 给出w,要求是否存在这样 ...