serega1112

338

Jan 26th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. class Solution:
  2.     def countBits(self, num: int) -> List[int]:
  3.        
  4.         dp = [0] * (num + 1)
  5.         dp[0] = 0
  6.        
  7.         diff = 1
  8.         steps = 1
  9.         for i in range(1, num+1):
  10.             if steps:
  11.                 steps -= 1
  12.             else:
  13.                 diff *= 2
  14.                 steps = diff - 1
  15.             dp[i] = dp[i-diff] + 1
  16.            
  17.         return dp
Advertisement
Add Comment
Please, Sign In to add comment