Skip to content

Bug Report for counting-bits #4943

@haoboliu66

Description

@haoboliu66

Bug Report for https://neetcode.io/problems/counting-bits

It's more of a question.
For a solution like this:

public class Solution { public int[] countBits(int n) { int[] res = new int[n + 1]; for (int num = 1; num <= n; num++) { for (int i = 0; i < 32; i++) { if ((num & (1 << i)) != 0) { res[num]++; } } } return res; } }

Why is the inner loop treated as O(logN) when n is always an integer and the bit length is always 32?
Shouldn't it be O(1)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions