LeetCode 357. Count Numbers with Unique Digits

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])


Seems like there is a rule for it.

if n == 1, there will be 10 numbers [0 -- 9]

if n == 2, since we can't start from 0, if we start from 1, there will be 1*9, start with 2, there will be 1 * 9..... thus, n == 2, in total = 1*9*9

if n ==3, since we can't start from 0, if we start from 1*, there will be 1*9*8, start with 2, there will be 1*9*8 ... thus n == 3, in total = 1*9*9*8

if n == 4, since we can't start from 0, if start with 1**, there will be 1*9*8*7, start with 2, 1*9*8*7.... n ==3, in total = 1*9*9*8*7

.... the total is n==1 + n==2 + ... n == n

int fn(n) {
  int n = 2;
  int prev = 10;
  int sum = 9;
 while(n > 1) {
    sum = sum * (9 - n + 2);
    total = prev + sum;
    n = n - 1;
  }
  return total;
}


Or use dp.

    int countNumbersWithUniqueDigits(int n) {
        if(!n) return 1;
        vector<int> dp(n, 0);
        dp[0] = 9;
        for(int i = 1; i < n; ++i) {
            dp[i] = dp[i-1] * (10 - i);
        }
        int sum = 0;
        for(int i = 0; i < n; ++i) sum += dp[i];
        return sum + 1;
    }
uniapp H5刷新页面后返回按钮失效问题完美解决方案 这个问题其实很隐蔽,尤其是uniapp H5 场景下刷新导致栈清理,很多开发者一开始都懵掉了。uniapp 内部对「页面栈只有一个」时的返回逻辑是reLaunch;所以只要在这个分支里替换为自己的逻辑(比如),就能顺利实现预期。目前我在项目里已经跑通了,暂时没发现问题。不得不说,知道源码里这个逻辑后,真的是醍醐灌顶,只能膜拜框架大佬了 🤯。 阅读详情

相关推荐

飞凌OK3588-C Linux R4系统下MIPI YUV摄像头CSI尺寸错误排查与极性适配方案

本文详细介绍了在飞凌OK3588-C平台的Linux R4系统下调试MIPI YUV摄像头时遇到的'csi size err'错误排查与极性适配方案。通过分析信号极性、驱动参数调整及FPGA协同调试,提供了从硬件检测到系统级调试的完整解决方案,帮助开发者快速解决类似问题。

bean的博客 257

LeetCode:357. Count Numbers with Unique Digits

LeetCode:357. Count Numbers with Unique DigitsGiven 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 tota

zems 530

Claude skill-creator插件深度解析:从创建到优化的完整技能工程化体系

摘要:skill-creator是Anthropic推出的Claude技能开发插件,提供从创建到优化的全流程工程化支持。其核心架构采用渐进式披露机制和多Agent协作模式,包含Grader、Analyzer等专业评估组件。该插件支持自动化评测系统,通过测试用例管理、并行执行和结果聚合实现技能验证;提供迭代优化算法,基于数据驱动改进技能性能。典型应用场景包括标准化技能开发、自动化测试验证和触发优化,显著降低开发门槛并提升技能质量。

虚心若愚 988

Leetcode 357 Count Numbers with Unique Digits

Leetcode 357 Count Numbers with Unique Digits

Raptor_2017的博客 374

Alipay 支付唤起 h5 测试

测试地址 https://recharge.apps.oppomobile.com/recharge-center/recharge/?from=message try { //唤起客户端快捷参数 var data = {"requestType":"SafePay","fromAppUrlScheme":"alipays","dataString":"h5_ro...

六桥风月IT随笔 1万+

Python 实战:手语翻译系统——从视频到文本的智能转换

今天,我们用 Python 构建了一个。

Echo_Wish 343

LeetCode 357. Count Numbers with Unique Digits 解题报告

LeetCode 357. Count Numbers with Unique Digits 解题报告

骆小坑的填坑之旅 1020

探索激光焊接光束质量诊断系统:原理、应用与前沿

激光焊接光束质量诊断系统是一套专门用于精确评估和监测激光焊接过程中光束特性的精密设备。它宛如一个精密的 “光束医生”,能够全方位地对激光光束进行 “体检”,为焊接工艺提供关键的数据支持。探测器:作为系统的 “感知触角”,探测器负责捕捉激光光束的各种信息,其性能直接影响着诊断的准确性。例如,常见的 CCD(电荷耦合器件)探测器和 CMOS(互补金属氧化物半导体)探测器,它们能够将光信号转化为电信号,具有高灵敏度、高分辨率等特点,可精确探测光束的强度分布、光斑位置等参数。光学透镜。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 2582

【LeetCode】357. Count Numbers with Unique Digits 计算各个位数不同的数字个数(Medium)(JAVA)

【LeetCode】357. Count Numbers with Unique Digits 计算各个位数不同的数字个数(Medium)(JAVA) 题目地址: https://leetcode.com/problems/count-numbers-with-unique-digits/ 题目描述: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10^n. Example:

qq_16927853的博客 211

【Claude Code 实战】第十章:DevOps 与 CI/CD 集成 / 光子AI

本章摘要:探讨Claude Code在DevOps与CI/CD集成中的应用。DevOps作为现代软件工程核心,结合AI技术实现自动化全流程,从代码提交到生产部署。通过CALMS模型(文化、自动化、精益、度量、分享)解析DevOps理念,对比传统瀑布模式与DevOps模式差异,展示AI如何加速Dockerfile编写、CI/CD配置等任务。典型示例显示AI可将原本30-60分钟的手动配置缩短至1-2分钟,大幅提升DevOps效率。

AI天才研究院 367

芯片标称具备8kVESD能力却在8kV测试中失效?

芯片级ESD(HBM模型)与系统级ESD(IEC 61000-4-2)存在本质差异:

硬核科技 644

【LEETCODE】357- Count Numbers with Unique Digits [Python]

【LEETCODE】357- Count Numbers with Unique Digits [Python]

aliceyangxi1987的博客 1317

pyecharts在jupyter notebook中不能够渲染图表问题。

在使用jupyter notebook中使用pyecharts绘制可视化图表的时候,发现图表不能渲染到页面中,生成的html是没问题的,本文主要解决在jupyter notebook中不能渲染这个问题。

猿小白的博客 1162

[leetcode] 357. Count Numbers with Unique Digits 解题报告

题目链接:https://leetcode.com/problems/count-numbers-with-unique-digits/ Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n. Example: Given n = 2, return 91. (

小榕流光的专栏 5629

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

[leetcode] 357. Count Numbers with Unique Digits

Description Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x &lt; 10n. Example: Input: 2 Output: 91 Explanation: The answer should be the total numbers in the rang...

Learning from the mistakes 246

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

LeetCode //C - 357. Count Numbers with Unique Digits

【代码】LeetCode //C - 357. Count Numbers with Unique Digits。

Made in Code 1180

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

LeetCode 357. Count Numbers with Unique Digits 题解(C++)

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

prayyojay的博客 398

[leetcode]357. Count Numbers with Unique Digits

题目链接:https://leetcode.com/problems/count-numbers-with-unique-digits/ Given anon-negativeinteger n, count all numbers with unique digits, x, where 0 ≤ x n. Example: Given n = 2, return

xiaocong1990的博客 231

Leetcode 357. Count Numbers with Unique Digits

题目链接问题描述Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x &lt; 10n.Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x &lt;...

SYSU_Chan的博客 274

leetcode 357 Count Numbers with Unique Digits C++

我的第一版解法  回溯法 int sum = 0; bool isUniqueDigit(int num) { if (num<10) return true; int tmp = num % 10; num /= 10; while(num) { if(tmp == num % 10) re

wcxdell的专栏 590

LeetCode—357. Count Numbers with Unique Digits

思路:题目要求找到所有没有重复数字构成的数,分解问题考虑: n位数包含了n-1位提供的所有答案,也就是说只要考虑n位数的情况。 在所有的n-1位数提供的答案中,n位数不重复的等于n-1位数的总和*(11-n),比如2位数,可以补充的选择是8个(则n-1=2;补充的数是10-2=8) public class Solution { List list;

徐玄清的专栏 811

LeetCode357. Count Numbers with Unique Digits

Given anon-negativeinteger n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Input: 2 Output: 91 Explanation: The answer should be the total numbers in the range of 0 ≤ ...

李歇特冯-兹拜因巴哈的博客 255

leetcode [357]Count Numbers with Unique Digits

Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Input: 2 Output: 91 Explanation: The answer should be the total numbers in the range of 0...

weixin_30883777的博客 95

【leetcode】357. Count Numbers with Unique Digits

一、题目描述 Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x [

小拳头的博客 336

LeetCode357. Count Numbers with Unique Digits题解

题目描述Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10^(n).

SYSU_LBY的博客 617

leetcode -- 357. Count Numbers with Unique Digits

Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Input: 2 Output: 91 Explanation: The answer should be the total numbers in the range of 0 ≤ x ...

猪の成长日记 226
上一篇: Design HashMap.
下一篇: Majority Element III
ActiveCoder
博客等级 码龄11年 4粉丝 345原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值