2
def findIntegers(self, n: int) -> int:3
b = bin(n).replace("0b", "")5
[[[-1 for i in range(2)] for i in range(2)] for i in range(2)]9
def fun(i, last, tight, leading_zeros):12
if dp[i][tight][leading_zeros][last] != -1:13
return dp[i][tight][leading_zeros][last]18
for j in range(end + 1):19
if j == 0 and leading_zeros == 1:20
res += fun(i + 1, j, tight & int(j == end), 1)23
res += fun(i + 1, j, tight & int(j == end), 0)26
res += fun(i + 1, j, tight & int(j == end), 0)27
dp[i][tight][leading_zeros][last] = res30
return fun(0, 0, 1, 1)