classSolution:defcountBits(self, n:int)-> List[int]:
re =[0,1,1]
i =3while i <= n:if i %2==0:
re.append(re[int(i/2)])else:
re.append(re[i-1]+1)
i +=1return re[:n+1]
338. 比特位计数因为奇数要比前一个偶数多一个0次方上的1,而偶数除以2相当于整个二进制右移保持1的个数不变class Solution: def countBits(self, n: int) -> List[int]: re = [0, 1, 1] i = 3 while i <= n: if i % 2 == 0: re.append(re[int(