解题报告-1012. Numbers With Repeated Digits
Given a positive integer N, return the number of positive integers less than or equal to N that have at least 1 repeated digit.
Example 1:
Input: 20
Output: 1
Explanation: The only positive number (<= 20) with at least 1 repeated digit is 11.
Example 2:
Input: 100
Output: 10
Explanation: The positive numbers (<= 100) with atleast 1 repeated digit are 11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.
Example 3:
Input: 1000
Output: 262
Note:
1 <= N <= 10^9
class Solution(object):
def numDupDigitsAtMostN(self, N):
"""
:type N: int
:rtype: int
"""
list_n = map(int, str(N + 1))
res = 0
len_n = len(list_n)
def get_cnt(m, n):
if 0 == n:
return 1
return get_cnt(m, n - 1) * (m - n + 1)
for i in range(1, len_n):
res += 9 * get_cnt(9, i - 1)
s = set()
for i, x in enumerate(list_n):
for y in range(0 if i else 1, x):
if y in s:
continue
res += get_cnt(9 - i, len_n - i - 1)
if x in s:
break;
s.add(x)
return N - res
# return get_permutation_cnt(3)
解题报告-1012. Numbers With Repeated Digits的更多相关文章
- 【leetcode】1012. Numbers With Repeated Digits
题目如下: Given a positive integer N, return the number of positive integers less than or equal to N tha ...
- leetcode_1015. Numbers With Repeated Digits
https://leetcode.com/problems/numbers-with-repeated-digits/ 与leetcode_357. Count Numbers with Unique ...
- Numbers With Repeated Digits
2020-01-03 12:01:46 问题描述: 问题求解: 确实可以当作数学题去做,但是要分类讨论什么的还是有点麻烦的. 这个时候万能的dfs上场了,直接暴力检索,真的太强了. int res = ...
- 【LeetCode】357. Count Numbers with Unique Digits 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【LeetCode】129. Sum Root to Leaf Numbers 解题报告(Python)
[LeetCode]129. Sum Root to Leaf Numbers 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/pr ...
- 【LeetCode】165. Compare Version Numbers 解题报告(Python)
[LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- 【九度OJ】题目1012:畅通工程 解题报告
[九度OJ]题目1012:畅通工程 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1012 题目描述: 某省调查城镇交通状况 ...
- 【九度OJ】题目1442:A sequence of numbers 解题报告
[九度OJ]题目1442:A sequence of numbers 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1442 ...
- 【LeetCode】738. Monotone Increasing Digits 解题报告(Python)
[LeetCode]738. Monotone Increasing Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu ...
随机推荐
- Hosts 文件的作用
问题来源: 我修改了hosts文件访问公司的内网 但是出现错误找不到服务器或DNS错误 一个下午了都上不了公司的系统. Hosts是什么?Hosts是Window系统目录里的一个文件,它的作用可大 ...
- Linux运维学习笔记-软硬链接知识总结
文件链接 硬链接,通过索引节点来进行链接 硬链接原理图 硬链接的创建: 直接执行命令“ln 源文件 硬链接文件”,即可完成创建硬链接. 硬链接知识小结: 1.具有相同Inode节点号的多个文件是互 ...
- js:关闭当前页面
var userAgent = navigator.userAgent; if (userAgent.indexOf("Firefox") != -1 || userAgent.i ...
- debian 安装deb软件
deb包 deb包是debian,ubuntu等LINUX发行版的软件安装包,是类似于rpm的软件包,而非debian,ubuntu系统不推荐使用deb软件包,因为要解决软件包依赖问题,安装也比较麻烦 ...
- BZOJ3195: [Jxoi2012]奇怪的道路【状压DP】
Description 小宇从历史书上了解到一个古老的文明.这个文明在各个方面高度发达,交通方面也不例外.考古学家已经知道,这个文明在全盛时期有n座城市,编号为1..n.m条道路连接在这些城市之间,每 ...
- Spring Model存储值在jsp EL表达式中不能正确显示(原样显示)问题
这几天我搭了一个SpringMvc环境,写了一个Controller,并且Controller里面有一个很简单的映射到jsp页面的方法,如下: 这里的Map<String,String>其 ...
- 高性能优化规范建议Mysql
Mysql高性能优化规范建议 https://www.cnblogs.com/huchong/p/10219318.html 数据库命令规范 所有数据库对象名称必须使用小写字母并用下划线分割 所有数据 ...
- ehci ohci 驱动逻辑
1. EHCI ehci_platform_probe: platform_get_irq usb_hcd_request_irqs usb_hcd_irq 使用的是ehci的irq hcd-> ...
- DB2经常使用命令
1.打开命令行窗体 #db2cmd 2.打开控制中心 # db2cmd db2cc 3.打开命令编辑器 db2cmd db2ce =====操作数据库命令===== 4.启动数据库实例 #db2s ...
- 关于oracle的profiles
一.关于oracle的profiles profiles文件是口令和资源限制的配置集合,包括CPU的时间.I/O的使用.空闲时间.连接时间.并发会话数量.密码策略等对于资源的使用profile可以做到 ...