Advertisement
LikeRampage

Python3 Leetcode 338. Counting Bits Chatgpt

May 2nd, 2024
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | Software | 0 0
  1. class Solution:
  2.     def countBits(self, n: int) -> List[int]:
  3.         bits = [0] * (n + 1)
  4.         offset = 1
  5.         for i in range(1, n + 1):
  6.             if offset * 2 == i:
  7.                 offset *= 2
  8.             bits[i] = bits[i - offset] + 1
  9.         return bits
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement