leecode 357
来源:互联网 发布:二季度经济数据 编辑:程序博客网 时间:2024/05/11 20:37
357. Count Numbers with Unique Digit
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]
)
几点注意:
1.数字为0—9,10个
2.n>10 是 取n=10
3.rel[0] = 1;
rel[1] = 10;
rel[2] = rel[1] + (1~9)9 * (0~9去掉前面的)9
rel[3] = rel[2] + (1~9, 设取a)9*(0~9除了a,设取b)9*(0~9除ab)8
以此类推~~~~
class Solution {
public:int countNumbersWithUniqueDigits(int n) {
if (n == 0)
return 1;
if(n == 1)
return 10;
if (n == 2)
return 91;
if (n > 10)
n = 10;
int* rel = new int [n];
int del = 9;
rel[0] = 1;
rel[1] = 10;
rel[2] = 10 + 9*9;
for (int i = 3 ; i <= n ; i ++)
{
rel[i] = 9;
for (int j = 1 ; j < i ; j ++)
rel[i] *= 10-j;
rel[i] += rel[i-1];
}
return rel[n];
}
};
0 0
- leecode 357
- leecode
- LeeCode
- leecode 1
- leecode 2
- leecode 3
- leecode 6
- leecode:combinations
- Leecode刷题
- Leecode Week1
- LeeCode Week2
- [LeeCode]Edit Distance
- leecode Partition List
- leecode Decode Ways
- LeeCode]Edit Distance
- [LeeCode] Insertion Sort List
- LeeCode 边界条件注意
- LeeCode partition List
- Django:Exception Value: Invalid HTTP_HOST header 解决方法
- JS学习笔记_3_数组
- spring mvc ant path
- Ubuntu16.4安装Anaconda
- 设计模式系列-javaIO流与装饰模式
- leecode 357
- LeetCode之Excel Sheet Column Number
- Java 之 volatile关键字
- Python入门(五)Python数字、字符串、Unicode字符串
- 如何向Github上提交代码?
- 通过 floating IP 访问 VIP
- 启用 Open vSwitch
- OVS 中的各种网络设备
- 创建 OVS Local Network