Leetcode 357. Count Numbers with Unique Digits

这篇具有很好参考价值的文章主要介绍了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)文章来源地址https://www.toymoban.com/news/detail-827325.html

Code

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

到了这里,关于Leetcode 357. Count Numbers with Unique Digits的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • c语言Have Fun with Numbers

    Have Fun with Numbers Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again! Now you are suppo

    2024年02月02日
    浏览(27)
  • LeetCode笔记:Weekly Contest 357

    LeetCode笔记:Weekly Contest 357 1. 题目一 1. 解题思路 2. 代码实现 2. 题目二 1. 解题思路 2. 代码实现 3. 题目三 1. 解题思路 2. 代码实现 4. 题目四 比赛链接:https://leetcode.com/contest/weekly-contest-357 给出题目一的试题链接如下: 2810. Faulty Keyboard 1. 解题思路 这一题就是按照题目给出的条

    2024年02月14日
    浏览(27)
  • found input variables with inconsistene numbers of samples:[] 报错处理

    在用train_text_spilt进行机器学习的训练时候,出现了以下的报错:  代码检查发现错误 : train_x,train_y,test_x,test_y=train_test_split() train_x,train_y的行数不一致 应该改为: train_x,test_x,train_y,test_y=train_test_split()  

    2024年02月15日
    浏览(29)
  • leetcode 445. Add Two Numbers II(两数相加)

    用链表代表2个数字,这2个数字相加的和用链表返回。 最高位在链表的head. 思路: 1.链表逆序 数字相加是从低位到高位的,然而链表中的数字是从高位指向低位。 所以涉及到链表的逆序。 逆序之后只需从head到tail把两个链表的数字相加,再用一个int表示进位。 链表的逆序

    2024年02月16日
    浏览(32)
  • Leetcode 1022. Sum of Root To Leaf Binary Numbers (树遍历题)

    Sum of Root To Leaf Binary Numbers Easy 3.3K 183 Companies You are given the root of a binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is 0 - 1 - 1 - 0 - 1, then this could represent 01101 in binary, which is 13. For all leaves in the tree, cons

    2024年02月03日
    浏览(40)
  • 【排列组合】个人练习-Leetcode-62. Unique Paths

    题目链接:https://leetcode.cn/problems/unique-paths/ 题目大意:一个机器人从 m*n 的矩阵的左上角出发,目的地是右下角,每次只能向下或向右移动一格,求不同的路径的数量。 思路:就是排列组合。矩阵是 m*n ,实际上就是向下走 m-1 步,向右走 n-1 步,有多少种走法。 或者更简化

    2024年02月01日
    浏览(77)
  • LeetCode467. Unique Substrings in Wraparound String——动态规划

    We define the string base to be the infinite wraparound string of “abcdefghijklmnopqrstuvwxyz”, so base will look like this: “…zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd…”. Given a string s, return the number of unique non-empty substrings of s are present in base. Example 1: Input: s = “a” Output: 1 Explanation: Only the subst

    2024年02月19日
    浏览(36)
  • 【LeetCode 算法】Unique Paths III 不同路径 III 暴力DFS

    在二维网格 grid 上,有 4 种类型的方格: 1 表示起始方格。且只有一个起始方格。 2 表示结束方格,且只有一个结束方格。 0 表示我们可以走过的空方格。 -1 表示我们无法跨越的障碍。 返回在四个方向(上、下、左、右)上行走时,从起始方格到结束方格的不同路径的数目

    2024年02月14日
    浏览(37)
  • Leetcode 3045. Count Prefix and Suffix Pairs II

    Leetcode 3045. Count Prefix and Suffix Pairs II 1. 解题思路 2. 代码实现 题目链接:3045. Count Prefix and Suffix Pairs II 这一题的话思路上就是一个Trie树的思路来寻找前序字符,然后由于题目要求要同时满足前序和后序两个条件,因此找到每一个单词的前序子串之后再判断一下其是否同时为后

    2024年02月21日
    浏览(30)
  • LeetCode 2409. Count Days Spent Together【前缀和,容斥原理】简单

    本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,

    2023年04月17日
    浏览(27)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包