Leetcode 357. Count Numbers with Unique Digits

Problem

Given an integer n, return the count of all numbers with unique digits, x, where 0 < = x < 1 0 n 0 <= x < 10^n 0<=x<10n.

Algorithm

f(0) = 1
f(1) = 10
f(k) = 9 * 9 * 8 * … * (9 - k + 2)

Code

class Solution:
    def countNumbersWithUniqueDigits(self, n: int) -> int:
        ans = [1, 10, 91, 739, 5275, 32491, 168571, 712891, 2345851]
        return ans[n]

相关推荐

  1. Leetcode 377 组合总和 Ⅳ

    2024-02-19 17:34:02       47 阅读
  2. Leetcode 337 打家劫舍 III

    2024-02-19 17:34:02       42 阅读
  3. leetcode397周赛场

    2024-02-19 17:34:02       33 阅读
  4. LeetCode 367, 56, 22

    2024-02-19 17:34:02       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-19 17:34:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-19 17:34:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-19 17:34:02       87 阅读
  4. Python语言-面向对象

    2024-02-19 17:34:02       96 阅读

热门阅读

  1. RabbitMQ:分布式系统中的高效消息队列

    2024-02-19 17:34:02       53 阅读
  2. 二级 C 语言笔试-15

    2024-02-19 17:34:02       41 阅读
  3. 【vue】组件通信方式介绍

    2024-02-19 17:34:02       52 阅读
  4. 从零实现softmax回归【基于Pytorch】

    2024-02-19 17:34:02       55 阅读
  5. 使用docker搭建php开发环境

    2024-02-19 17:34:02       66 阅读
  6. 怎么测试阿里云香港服务器是不是cn2?

    2024-02-19 17:34:02       56 阅读