Skip to content

LeetCode 338: Counting Bits #69

@github-actions

Description

@github-actions

LeetCode 338: Counting Bits

Category: Binary
Difficulty: See LeetCode
Solution File: src/binary/counting_bits.py
Test File: tests/test_counting_bits.py

Problem Description

Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n),
ans[i] is the number of 1's in the binary representation of i.

Example 1:
Input: n = 2
Output: [0,1,1]

Example 2:
Input: n = 5
Output: [0,1,1,2,1,2]

Constraints:

  • 0 <= n <= 10^5

Tasks

  • Implement the solution in src/binary/counting_bits.py
  • Ensure all test cases pass
  • Analyze time complexity
  • Analyze space complexity

Metadata

Metadata

Assignees

No one assigned

    Labels

    binaryBlind 75 - Binary problemsblind-75Blind 75 - Blind-75 problems

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions