LeetCode Count Numbers with Unique Digits(计数问题)
题意:给出一个整数,求在[0,10^n]之间各位数字不相同的数的个数
思路:n为1时,有10个
n为2时, 十位数只能是1-9,而个数位可以为0,所以也是有9种选择
n为3时,百位数有9种选择,十位数有9种选择,个数数有8种选择
依此类推
代码如下:
public class Solution
{public int countNumbersWithUniqueDigits(int n){if (0 == n) return 1;else if (1 == n) return 10;int sum = 10;int dp = 9;for (int i = 2; i <= n; i++){dp *= 11 - i;sum += dp;}return sum;}
}
LeetCode Count Numbers with Unique Digits(计数问题)相关推荐
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- LeetCode 357. Count Numbers with Unique Digits
357. Count Numbers with Unique Digits Given a non-negative integer n, count all numbers with unique ...
- 357. Count Numbers with Unique Digits
357. Count Numbers with Unique Digits Given a non-negative integer n, count all numbers with unique ...
- leetcode -- 357. Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- leetcode 357. Count Numbers with Unique Digits | 357. 计算各个位数不同的数字个数(Java)
题目 https://leetcode.com/problems/count-numbers-with-unique-digits/ 题解 只要认真分析数字特点,这题不难,就是个带一些条件的排列组合. ...
- mysql unique count_MySQL - Count Number of Unique Values
问题 If I have three columns: orderNumber, name, email and I would like to count how many unique email ...
- pandas使用nunique函数计算dataframe每个数据列的独特值的个数(count number of unique values in each column of dataframe)
pandas使用nunique函数计算dataframe每个数据列的独特值的个数(count number of unique values in each column of dataframe) ...
- LeetCode Count Complete Tree Nodes(二分法)
问题:给出一个完全二叉树,求其结点个数 思路:第一种方式时直接使用递归法,将其左子树个数加上右子树个数再加上根结点 第二种方式二分法,因为完全二叉树除了最后一层外,其它都满足有2^i个结点,而最后一层 ...
- [LeetCode] Count Primes
Description: Count the number of prime numbers less than a non-negative number, n 解题思路 采用Eratosthene ...
最新文章
- day002-HTML知识点总结:浏览器兼容性之指定IE浏览器使用chrome内核渲染页面
- 跨链Cosmos(3)IBC协议
- php好玩的源码_github上比较有趣的PHP开源项目
- 计算机基础及wps office应用_自考本科计算机应用基础考试大纲
- 【RK3399Pro学习笔记】二、Thinker Edge R 内网穿透以实现远程SSH
- 因为此网站使用了 hsts_HSTS原理及实践
- 软件测试——测试用例的编写
- 关于ESAPI无法打印debug级别日志
- 春节期间,哪些信用卡取现不用手续费?
- XML编程(CRUD)
- 软件工程-软件维护/系统维护
- mysql最左前缀原则学习笔记,in也可以走索引
- 香港流行乐坛三十年(很好的回忆)
- sql注入预防 [ 光影人像 东海陈光剑 的博客 ]
- 计算机系统基础实验 - 同符号浮点数加法运算/无符号定点数乘法运算的机器级表示
- CAS4.0配置Mysql数据库,认证失败
- 美通企业周刊 | 中国平安将深度参与深圳公共住房建设;北京环球度假区将引入IMAX影院...
- 商品的SKU与SPU
- 在windbg中测试shadow ssdt , win32k!NtUserGetForegroundWindow , hook shadow ssdt
- 百度推广计划改为计算机端,百度推广怎么样搭建一个优秀的推广计划
热门文章
- 推荐MIT的电路与电子学
- vs目录(继承的值)配置
- UVA 10167 - Birthday Cake
- 求用1,2,5这三个数不同个数组合的和为100的组合个数
- mysql @pdept_MySQL 基本管理与常用sql 归结
- matlab dsp工具箱_GPU中的并行运算,加速你的Matlab程序
- 风变编程的python课程怎么样-高效学风变编程Python,解锁不一样的职场进阶之路...
- 基于python物流管理系统毕业设计-Python程序设计实验报告八:文件
- python官网下载步骤64位-电脑64位怎么下载python
- python画图-python画图的两种方法