给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n。
示例:
给定 n = 2,返回 91。(答案应该是除[11,22,33,44,55,66,77,88,99]外,0 ≤ x < 100 间的所有数字)

详见:https://leetcode.com/problems/count-numbers-with-unique-digits/description/

C++:

class Solution {
public:
int countNumbersWithUniqueDigits(int n) {
if (n == 0)
{
return 1;
}
int res = 0;
for (int i = 1; i <= n; ++i)
{
res += count(i);
}
return res;
}
int count(int k)
{
if (k < 1)
{
return 0;
}
if (k == 1)
{
return 10;
}
int res = 1;
for (int i = 9; i >= (11 - k); --i)
{
res *= i;
}
return res * 9;
}
};

参考:https://www.cnblogs.com/grandyang/p/5582633.html

最新文章

  1. Web项目中删错文件怎么办
  2. 【前台 submit的重复提交 错误】submit的重复提交
  3. Linux 下没有conio.h 已解决
  4. 如何设置修改WPS批注上的用户信息名称
  5. xcode语法高亮插件
  6. ios9邮箱添加163邮箱
  7. 设置开机启动时指定非ROOT用户执行相应的脚本
  8. js 保留两位小数
  9. sim卡中短信简要格式
  10. python_基础学习_03_正则替换文本(re.sub)
  11. git的初步使用---本地代码库的使用和提交
  12. BZOJ 3211: 花神游历各国【线段树区间开方问题】
  13. 从壹开始前后端分离 [ vue + .netcore 补充教程 ] 二九║ Nuxt实战:异步实现数据双端渲染
  14. Docker的介绍及安装
  15. 2018-2019-2 网络对抗技术 20165206 Exp3 免杀原理与实践
  16. AppStore关键词覆盖法则标记
  17. 多线程之BlockingQueue中 take、offer、put、add的一些比较
  18. Android设置屏幕旋转后保存数据
  19. Asp.Net Newtonsoft.Json使用教程
  20. 初探和实现websocket心跳重连(npm: websocket-heartbeat-js)

热门文章

  1. python文件读写及形式转化和CGI的简单应用
  2. ndk编译libpcap 1.7.4(最终解决方法)
  3. MySQL 分库、分表
  4. 【Codeforces 375A】Divisible by Seven
  5. 洛谷 P3203 BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊
  6. [luoguP2680] 运输计划(lca + 二分 + 差分)
  7. 【BZOJ3238】差异(后缀数组,单调栈)
  8. lombok中的@ToString注解作用
  9. MYSQL中插入数据以及修改数据的部分方法
  10. 洛谷 P2683 小岛