You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""i: the current index of the digit arrayisPrefix: if the new number is the prefix of NisBigger: if the new number will be bigger than N when we reach final positionExtra parameters need to be added to the dp function depends on the problem"""# upper bound of the digit arrayA=list(map(int, str(n)))
@cachedefdp(i, isPrefix, isBigger, *args):
ifi==len(A): return0ans=0fordinrange(i==0, 10):
_isPrefix=isPrefixandd==A[i]
_isBigger=isBiggeror (isPrefixandd>A[i])
ifCONDITIONandnot(i==len(A)-1and_isBigger):
# update answerans+=dp(i+1, _isPrefix, _isBigger, *args)
returnansreturndp(0, True, False)