2020-01-03 12:01:46

问题描述

问题求解

确实可以当作数学题去做,但是要分类讨论什么的还是有点麻烦的。

这个时候万能的dfs上场了,直接暴力检索,真的太强了。

    int res = 0;
public int numDupDigitsAtMostN(int N) {
dfs(0, 0, N);
return N - res + 1;
} private void dfs(long curr, int used, int N) {
if (curr > N) return;
res += 1;
for (int i = 0; i < 10; i++) {
if (i == 0 && used == 0) continue;
if ((used & (1 << i)) > 0) continue;
dfs(curr * 10 + i, used | (1 << i), N);
}
}

  

Numbers With Repeated Digits的更多相关文章

  1. leetcode_1015. Numbers With Repeated Digits

    https://leetcode.com/problems/numbers-with-repeated-digits/ 与leetcode_357. Count Numbers with Unique ...

  2. 解题报告-1012. Numbers With Repeated Digits

    Given a positive integer N, return the number of positive integers less than or equal to N that have ...

  3. 【leetcode】1012. Numbers With Repeated Digits

    题目如下: Given a positive integer N, return the number of positive integers less than or equal to N tha ...

  4. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  5. Count Numbers with Unique Digits

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  6. Leetcode: Count Numbers with Unique Digits

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  7. 357. Count Numbers with Unique Digits

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  8. 【Leetcode】357. Count Numbers with Unique Digits

    题目描述: Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. ...

  9. [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 ...

随机推荐

  1. 查漏补缺:进程间通信(IPC):FIFO

    1.FIFO FIFO,又称命名管道.不同于pipe管道的只能用于拥有共同祖先进程的两个进程间通信,因FIFO通过路径绑定,所以即使是不相关的进程间也可通过FIFO进行数据交换. FIFO是一种文件类 ...

  2. View 属性

    关于 View 设置属性的方式: JavaxmlstyledefStyleAttrdefStyleResTheme 关于 defStyleRes 的使用,和在 xml 中声明 style=" ...

  3. 人心和隐私怎么防?“防出轨”APP让道德滑落

    ​ 王尔德曾说过,"一个人应该永远保持一点神秘感".让·保·里克特也表示,:"一个人泄露了秘密,哪怕一丝一毫,就再也得不到安宁了".可见,对于自然人来说,保有自 ...

  4. Context与ApplicationContext的区别

    ApplicationContext并没有这个类,其实更应该叫做:Activity与Application在作为Context时的区别.嗯,的确是这样的,大家在需要Context的时候,如果是在Act ...

  5. Python:turtle库的使用及图形绘制

    目录 一.绘制一个八边形 二.绘制一个八角图形 三.简述问题 四.循环程序设计 五.绘制一个自己喜欢的图形 一.绘制一个八边形 使用turtle库,绘制一个八边形 代码: from turtle im ...

  6. 常见WAF绕过思路

    WAF分类 0x01 云waf 在配置云waf时(通常是CDN包含的waf),DNS需要解析到CDN的ip上去,在请求uri时,数据包就会先经过云waf进行检测,如果通过再将数据包流给主机. 0x02 ...

  7. Codeforces Round #295 (Div. 2) B. Two Buttons 520B

    B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  8. ZYNQ入门实例——定时器中断与程序固化

    一.前言 APU系统中CPU以串行执行代码的方式完成操作,软件方式很难做到精准计时,因此调用内部定时器硬件完成计时是更好的选择.本文以定时器中断方式控制LED周期性闪烁为例学习私有定时器的使用.同时学 ...

  9. 大型Java进阶专题(二) 软件架构设计原则(上)

    前言 ​ 今天开始我们专题的第一课了,也是我开始进阶学习的第一天,我们先从经典设计思想开始,看看大牛市如何写代码的,提升技术审美.提高核心竞争力.本章节参考资料书籍<Spring 5核心原理&g ...

  10. idea创建简单web项目分析Servlet的请求转发与重定向的区别

     注:如需转载,请附上原文链接,如有建议或意见,欢迎批评指正! 需求说明: // index.jsp页面 1 <% 2 String basePath = request.getScheme() ...