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. sycPHPCMS v1.6 cookie sqlinjection

    ./user/index.php include "../include/conn.php"; include "../include/function.php" ...

  2. C++走向远洋——61(项目一、排序函数模板)

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  3. property 属性

    #propery 属性"""内置装饰器函数,只在面向对象中使用."""#计算圆的面积,圆的周长 from math import pi cl ...

  4. LeetCode--链表1-单链表

    LeetCode--链表1-单链表 单链表模板 初始化 头部插入 尾部插入 删除节点 Index插入 Index返回对应的节点指针和val值 class MyLinkedList { private: ...

  5. 随手撸一个简单的带检查的printf

    #include <stdio.h> #include <iostream> #include <vector> #include <string> # ...

  6. IAR软件使用的快捷键配置以及配置cc2530环境

    以下是我对IAR软件使用的快捷键配置cc2530以及配置环境的总结,如下图所示 ​ ​ ​ 弹出保存窗口 ​ 工程生成完毕——生成.c文件 ​ 快捷键ctrl+s保存.c文件 ​ ​ ​ ​ ​ 选择 ...

  7. RocketMQ - 基础知识

    RocketMQ简介 RocketMQ是阿里开源的消息中间件,它是纯java开发,具有低延迟.高吞吐量.高可用性和适合大规模分布式系统应用的特点.从名字可以看出Rocket火箭,代表RocketMQ主 ...

  8. vue-cli “从入门到放弃”

    主要作用:目录结构.本地调试.代码部署.热加载.单元测试 在如今前端技术飞速发展的时代,angular.js.vue.js 和 react.js 作为前端框架已经呈现出了三国鼎立的局面.作为国人若你不 ...

  9. 【每日一包0018】fecha

    [github地址:https://github.com/ABCDdouyae...] fecha 比moment.js更加轻量级的时间解析和格式化包 format 用法:format(<Dat ...

  10. 内存:你跑慢点行不行?CPU:跑慢点你养我吗?内存:我不管!(内附超全思维导图)

    主存(RAM) 是一件非常重要的资源,必须要认真对待内存.虽然目前大多数内存的增长速度要比 IBM 7094 要快的多,但是,程序大小的增长要比内存的增长还快很多.不管存储器有多大,程序大小的增长速度 ...