/*
Given a non-negative integer n, count all numbers with unique digits,
x, where 0 ≤ x < 10^n.
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])
*/
/*
思路:
要想数字不一样,用到数学中的排列组合:
当n=1时;
因为只有一个数字,所以0-9都是答案.
当n>=2时;
第一位是非0,则有9种情况
第二位和第一位不同,也有9种情况
第三位有8种情况
......
*/
public class Solution {
public int countNumbersWithUniqueDigits(int n) {
if(n == 0) {
return 1;
}
if(n == 1) {
return 10;
}
int digits = 9,
val = 10;
for(int i = 2;i <= n;i++) {
digits = digits*(9 - i + 2);
val = val + digits;
}
return val;
}
}
相关推荐
华为云Stack交付实战:从工勘到上线的全流程拆解
本文详细拆解华为云Stack交付全流程,从项目启动、工勘、LLD设计到硬件部署和软件安装,提供实战技巧与避坑指南。重点解析华为云Stack交付流程中的关键环节,如标准化工具使用、规范化文档管理和流程化协作,帮助团队高效完成从工勘到上线的复杂项目交付。
Leetcode--Java--357. 计算各个位数不同的数字个数
题目描述 给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n 。 样例描述 示例: 输入: 2 输出: 91 解释: 答案应为除去 11,22,33,44,55,66,77,88,99 外,在 [0,100) 区间内的所有数字。 思路 排列组合 + 总结递推规律 如果是5位数,方案数如下 n最大为10,否则没有意义,因为0~9刚好10种数位,如果n大于10一定会有重复 找规律,例如如果n等于6,相当于在上面例子后面再乘5,同理n等于7,就是再乘4,所以递
手把手教你为ArduPilot添加自定义飞行模式:以自动巡检航线为例
本文详细介绍了如何为开源飞控ArduPilot添加自定义飞行模式,并以自动巡检航线为例,提供了从状态机设计、代码实现到地面站集成的完整开发指南。通过七步法手把手教学,帮助开发者深入理解飞控核心逻辑,实现无人机自主执行复杂巡检任务,满足行业应用定制需求。
[leetcode-357]Count Numbers with Unique Digits(java)
思路:这道题要求0<=x < 10^n的不重复数字的个数。因此,我们可以考虑1位时、2位时、3位时。。。然后累加起来。 注意此时首位不为0。 代码如下:public class Solution { public int countNumbersWithUniqueDigits(int n) { int sum = 0; if(n <= 10){
AI中台系统设计方案探讨
集成JupyterLab、低代码建模工具(如H2O.ai)、预训练模型库(Hugging Face、PaddleHub)。:通过REST/gRPC接口封装AI能力(如OCR、语音识别),支持流量控制与鉴权(如Kong、Apigee)。:服务注册发现(Consul)、熔断降级(Hystrix)、监控告警(Prometheus+Grafana)。:分布式存储(如HDFS、Ceph)与对象存储(如S3、OSS),支持海量数据高速读写。加密传输(TLS)、动态脱敏(如数据掩码)、访问控制(RBAC)。
实战解析:如何用Python逆向破解FastMoss的TikTok数据加密签名(附完整代码)
本文详细解析了如何用Python逆向破解FastMoss平台的TikTok数据加密签名机制,包括MD5加密算法和JS逆向分析。通过完整的Python代码示例,帮助开发者理解签名生成原理并实现自动化请求,提升数据获取能力。
[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. (
手把手教你用C语言给STM32写一个Modbus RTU从机库(含完整项目源码)
在工业自动化领域,Modbus RTU协议因其简单可靠的特点,成为RS485总线通信的事实标准。对于嵌入式开发者而言,为STM32等微控制器实现一个高效的Modbus RTU从机协议栈,是开发智能传感器、执行器等设备的必备技能。Modbus RTU从机的核心是一个状态机,需要处理帧接收、CRC校验、功能码解析和响应生成等环节。工业现场总会遇到意想不到的干扰情况,一个健壮的协议栈应该能够优雅地处理各种异常场景,而不是简单地崩溃或死锁。工业现场环境复杂,协议栈必须具备完善的异常处理机制。
JAVA程序设计: 计算各个位数不同的数字个数(LeetCode:357)
给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n。 示例: 输入: 2 输出: 91 解释: 答案应为除去 11,22,33,44,55,66,77,88,99 外,在 [0,100) 区间内的所有数字。 思路:附上我在LeetCode上写的题解,思路非常清晰、代码简介。 class Solution { public int c...
动态规划与状态压缩:从TSP问题理解算法优化核心思想
动态规划是一种通过将复杂问题分解为重叠子问题并存储中间结果来避免重复计算的核心算法思想,广泛应用于路径优化、资源分配和序列决策等场景。其核心原理在于最优子结构和无后效性,通过状态设计和状态转移方程,将指数级复杂度问题转化为多项式时间可解。在工程实践中,状态压缩技术常被用于高效表示集合状态,例如使用二进制位运算来操作城市访问集合,从而大幅提升算法效率。本文以经典的旅行商问题(TSP)为例,深入剖析如何运用动态规划与状态压缩技术,将暴力穷举的指数级复杂度优化为可管理的计算量,为解决组合优化问题提供了重要的方法论
【软件系统架构】系列十一:面向对象技术—sysML
摘要: SysML(系统建模语言)是UML的扩展,专为复杂系统工程设计,支持硬件、软件、人员等跨领域建模。其核心包括9种图:4种结构图(如块定义图BDD、内部块图IBD)、4种行为图(如活动图AD、序列图SD)和需求图(REQ),覆盖需求、结构、行为及参数约束。相比UML(面向软件),SysML精简图表(9 vs 13),强化需求追踪与性能分析(如参数图PD),并支持MBSE(基于模型的系统工程)。需求关系(如满足、验证、派生)在需求图中明确关联设计实现,形成闭环管理。SysML是UML的子集与系统工程扩展
【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:
极验点选click3.1.0所对应fullpage.js的逆向分析
极验3代点选验证,本文适用于使用click.3.1.0.js和fullpage919-eyz9lh.js版本的web验证码,没有细节内容,适合有基础的开发者阅读。
Java [Leetcode 357]Count Numbers with Unique Digits
题目描述: Given anon-negativeinteger 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 ≤ ...
visio安装包
Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。
Outlook Express 6 (OE6) for Win7/Win8/Win10
英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。
leetcode 357. Count Numbers with Unique Digits | 357. 计算各个位数不同的数字个数(Java)
题目 https://leetcode.com/problems/count-numbers-with-unique-digits/ 题解 只要认真分析数字特点,这题不难,就是个带一些条件的排列组合。 以 3 个数字 可以组成的不重复数字数量为例: 不包含重复数字的 3 位数 = 不包含重复数字的严格 2 位数 + 不包含重复数字的严格 3 位数(其中,本文所述的“严格”表示不以 0 开头。例如,034 不是严格三位数,但它是严格两位数) 代码就很简单了,递归可解。 class Solution {
jdk-8u144-linux-x64.tar.gz.
该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包
【LEETCODE】357- Count Numbers with Unique Digits [Python]
【LEETCODE】357- Count Numbers with Unique Digits [Python]
OV9734 DATASHEET,完整规格书
OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等
leetcode_357 Count Numbers with Unique Digits
题意分析:给定非负的整数n,求在0<=x<10^n中,有多少每个位上的数字互不相同的数?如n=2时,范围为[0,100],共有91个数(除了11,22,33,44,55,66,77,88,99)。 解题思路: 统计规律如下:i = 1时,10个 i = 2时,10个 + 9*9个 i = 3时,10个 + 9*9个 + 9*9*8个 i = 4时,10个 + 9*9个 + 9*9*8个 + 9*9*
【LeetCode】357. Count Numbers with Unique Digits
357. Count Numbers with Unique Digits My Submissions QuestionEditorial Solution Total Accepted: 1190 Total Submissions: 2830 Difficulty: Medium Given a non-negative integer n, count all numbers with
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 ...
LeetCode 357. Count Numbers with Unique Digits
357. Count Numbers with Unique Digits Medium 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 ...
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...
LeetCode笔记:357. Count Numbers with Unique Digits
计算唯一组成数出现的数量
【leetcode】357. Count Numbers with Unique Digits
题目: 思路: 规律如下: f(0)=1 f(1)=10 f(2)=9*9+f(1) f(3)=9*9*8+f(2) f(4)=9*9*8*7+f(3) f(5)=9*9*8*7*6+f(4) f(6)=9*9*8*7*6*5+f(5) f(7)=9*9*8*7*6*5*4+f(6) f(8)=9*9*8*7*6*5*4*3+f(7) f(9)=9*9*8*7*6*5*4*3*2+f(8) f(10)=9*9*8*7*6*5*4*3*2*1+f(9) 大于10的情况全为0,因为就10个数字,肯定都会重复
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 [11,22,33,44,
[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 [11,22,33,44,
LeetCode.357 Count Numbers with Unique Digits (统计数字不同的总数)
1.题目 Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. 2. 样例 Example: Input: 2 Output: 91 Explanation: The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,4
156



被折叠的 条评论
为什么被折叠?



