Home | Projects | Notes > Problem Solving > LC - E - 338. Counting Bits

LC - E - 338. Counting Bits

 

Solutions in C++

Solution 1

Complexity Analysis:

Solution:

 

Solution 2

This solution focuses on the relationship between the ith element and the (i/2)th element, and the relationship between odd and even elements. It has better time complexity than that of Solution 1's.

Complexity Analysis:

Solution:

Calling operator [], front(), and back() for an empty container always results in undefined behavior. Only at() operator checks for range validity.