解题报告-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 ...
随机推荐
- boost 中文编码转换
Lstring CHanderHttp::CircleDesc(Lint nCurCircle, Lint nMaxCircle,Lint usercount){ std::stringstream ...
- Linux上jdk安装及环境变量设置
1.jdk下载和安装 (1)http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html下载需 ...
- .net中的Dictionary字典类的使用方法
//定义字典 Dictionary<string, string> d = new Dictionary<string, string>(); //添加字典的元素 ; i &l ...
- 树莓派系列教程:安装系统与配置环境,使用PuTTy与VNC图形界面远程登录
本文所需物品清单: Raspberry Pi 3 Model B 主板.SD卡与读卡器(用于烧录系统) 资料整理来源在文尾 需要下载的资源与工具: 推荐系统-Raspbian 树莓派官方深度定制的硬件 ...
- pthread中向线程发送信号(pthread_kill )
pthread_kill 语法 int pthread_kill(thread_t tid, int sig); #include <pthread.h> #include <sig ...
- 【转】Linux下的文本dos格式转Unix格式,去除^M符号
原文网址:http://blog.csdn.net/kobejayandy/article/details/13291525 问:我在Windows中通过FTP传一个文本文件到Linux中,但是打开文 ...
- xmlns和xsi之schemaLocation
appplicationContex.xml文件报错:元素 "util:constant" 的前缀 "util" 未绑定 在根节点添加了“xmlns:util= ...
- brave-zipkin的日志源码分析
其实在zipkin的日志里面作为发送端日志两个,sr,ss,这个日志是servlet产生的:接收端日志是四个,分别是cr,sr,ss,cs:cr和cs分别是上游的日志的信息:ss和sr是接收端输出的日 ...
- 【monkeyrunner】monkeyrunner 实例
import time import os import re from com.android.monkeyrunner import MonkeyRunner as mr from com.and ...
- php代码编译的实现
1.php是解析型的高级语言,zend内核使用c语言实现,有main函数,php脚本就是输入,内核处理后输出结果,内核将php脚本翻译成c程序可识别的opcode就是php的编译. c语言的编译将c代 ...