Leetcode 0338. Counting Bits

Posted on Tue 17 December 2024 in Leetcode • Tagged with bits, dp

Question Link : https://leetcode.com/problems/counting-bits/

Difficulty: Easy

Premium: False

Question

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 …


Continue reading

Leetcode 0191. Number of 1 Bits

Posted on Mon 16 December 2024 in Leetcode • Tagged with bits

Question Link : https://leetcode.com/problems/number-of-1-bits/

Difficulty: Easy

Premium: False

Question

Given a positive integer n, write a function that returns the number of set bits in its binary representation (also known as the Hamming weight).   Example 1:

Input: n = 11 Output: 3 Explanation: The input binary string 1011 …


Continue reading

Leetcode 0190. Reverse Bits

Posted on Tue 19 November 2024 in Leetcode • Tagged with bits

Question Link : https://leetcode.com/problems/reverse-bits/

Difficulty: Easy

Premium: False

Question

Reverse bits of a given 32 bits unsigned integer. Note:

Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer …


Continue reading