357. Count Numbers with Unique Digits
来源:互联网 发布:淘宝有哪些ysl正品店 编辑:程序博客网 时间:2024/04/19 08:33
题目
Given a non-negative integer n, count all numbers with unique digits, x, where
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])
Credits:
Special thanks to @memoryless for adding this problem and creating all test cases.
分析
给定n, 给出
用排列组合的规律可以求出来:
10 + 9 * 9 + 9 * 9 * 8 + 9 * 9 * 8 * 7 + … (加到第10项之后就不必再加了.)
实现
0ms
class Solution {public: int countNumbersWithUniqueDigits(int n) { if (n == 0) return 1; int result = 10, pdt = 9; for (int i = 1; i < n; i++) { pdt *= (10 - i); result += pdt; if (i > 10) break; // 位数大于10必定有重复.不存在满足条件的数 } return result; }};
阅读全文
0 0
- 【LeetCode】357. Count Numbers with Unique Digits
- 357. Count Numbers with Unique Digits
- LeetCode 357. Count Numbers with Unique Digits
- [leetcode] 357. Count Numbers with Unique Digits
- 357. Count Numbers with Unique Digits
- 【LeetCode】357. Count Numbers with Unique Digits
- leetcode 357. Count Numbers with Unique Digits
- leetcode 357. Count Numbers with Unique Digits
- leetcode.357. Count Numbers with Unique Digits
- 357. Count Numbers with Unique Digits
- 357. Count Numbers with Unique Digits
- 357. Count Numbers with Unique Digits
- 357. Count Numbers with Unique Digits
- 357. Count Numbers with Unique Digits
- 357. Count Numbers with Unique Digits
- 357. Count Numbers with Unique Digits
- 357. Count Numbers with Unique Digits
- LeetCode:357. Count Numbers with Unique Digits
- 评论这篇《生老病死相互扶持这事真特么不是闹着玩的。》故事
- 百度网盘资源下载加速教学
- 国内用cnpm安装更新element-ui有很多不明错误,该怎样解决
- JavaScript 获取标签对象,创建标签对象
- Java
- 357. Count Numbers with Unique Digits
- 常用命令
- 乐观锁和悲观锁
- String、StringBuffer、StringBuilder
- long long 与int的区别
- 【转载】Jlink工具下的RTT调试应用
- gradle仓库配置
- char(10)和VARCHAR(10)主要的区别是什么?
- log4cxx配置文件(log4cxx.properties文件)详解 --调整日志输出级别