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])
代码如下:
public class Solution {
public int countNumbersWithUniqueDigits(int n) {
if(n==0)
return 1;
int sum=0,p=0;
if(n<=2)
return (int)Math.pow(9,n)+countNumbersWithUniqueDigits(n-1);
else{
sum=countNumbersWithUniqueDigits(n-1);
n=n-2;
p=81;
int q=8;
while(n>0)
{
p=p*q;
q--;
n--;
}
}
return sum+p;
}
}
357. Count Numbers with Unique Digits的更多相关文章
- LC 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
题目描述: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. ...
- Java [Leetcode 357]Count Numbers with Unique Digits
题目描述: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. ...
- 【LeetCode】357. Count Numbers with Unique Digits 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 357 Count Numbers with Unique Digits 计算各个位数不同的数字个数
给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n.示例:给定 n = 2,返回 91.(答案应该是除[11,22,33,44,55,66,77,88,99 ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- Leetcode: Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [Swift]LeetCode357. 计算各个位数不同的数字个数 | Count Numbers with Unique Digits
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
随机推荐
- Oracle内置函数内容整理
--绝对值select abs(-100) from dual; --取余select mod(8,3) from dual; --取整,大于该数的最小整数(上限值)select ceil(12.0) ...
- bzoj 2330: [SCOI2011]糖果
#include<cstdio> #include<iostream> using namespace std; ],next[],u[],v[],h,t,a[]; ],f[] ...
- Hibernate中的组合映射
1.实体bean设计 car: public class Car { private int id; private String name; private Wheel wheel; set... ...
- java中this的用法?
2008-07-28 08:10cztx5479 | 分类:JAVA相关 | 浏览4533次 java中this的用法? import java.awt.*; import java.awt.even ...
- vc设置按钮文字颜色
设置按钮文字颜色使用 CMFCBUTTON即可 在OnInitDialog函数加入如下内容即可 ((CMFCButton*)GetDlgItem(IDC_MFCBUTTON1))->SetTex ...
- (转)HTML文档头部信息
原文:http://www.cnblogs.com/sunyunh/archive/2012/07/25/2609199.html HTML(3)HTML文档头部信息 <!DOCTYPE h ...
- ant新建scp和sshexec任务
1.build.xml中新建targer如下: <target name="remotecopytest" description="拷贝文件到远程服务器" ...
- 如何安装php?
1.解压apache文件 2.进行注册,写地址,邮箱 3.下一步选择Typical 4.下一步随意选个安装路径 5.解压php文件 6.把php.ini-development文件改为php.ini ...
- PhP访问mysql数据库的基本方式
一,查询 <?php$conn= mysql_connect("127.0.0.1","lanou12","lanou12");$fi ...
- HDU5763 another meaning -(KMP+DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5763 思路:dp[i]表示前i个字符组成的字符串所表示的意思数量,则当匹配时dp[i]=dp[i-1] ...