第一次通过使用的代码:
import numpy
class Solution(object):
def numDupDigitsAtMostN(self,N):
"""
:type N: int
:rtype: int
"""
dig=1
num=0
inter=N
point=[]
while inter//10!=0:
dig+=1
point.append(inter%10)
inter=inter//10
point.append(inter%10)
if dig!=1:
for i in range(dig-2):
num+=9*fac(9,i+1)
n=0
num+=9
num+=(point[dig-1]-1)*fac(9,dig-1)
for i in range(2,dig+1):
m=0
inter=0
for j in range(1,i):
if point[dig-j]<point[dig-i]:
m+=1
if point[dig-j]==point[dig-i]:
inter=1
if n==0:
num+=(point[dig-i]-m)*fac(10-i,dig-i)
if inter==1:
n=1
if n==0:
for i in range(dig):
for j in range(i):
if point[j]==point[i]:
n=1
if n==0:
num+=1
if dig==1:
num=N
return N-num
def fac(maxm,dig):
fact=1
for i in range(dig):
fact=fact*(maxm-i)
if dig==0:
fact=1
return fact