Number of 1 Bits - Leetcode 191 - Python - English
The document discusses two algorithms for counting the number of set bits (ones) in a binary representation of an unsigned integer. The first algorithm counts the bits manually by shifting the number right by one bit at a time and checking the least significant bit. The second algorithm improves efficiency by only examining bits that are set to one using bitwise AND and subtraction operations. Both algorithms run in constant time O(1).
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
33 views
Number of 1 Bits - Leetcode 191 - Python - English
The document discusses two algorithms for counting the number of set bits (ones) in a binary representation of an unsigned integer. The first algorithm counts the bits manually by shifting the number right by one bit at a time and checking the least significant bit. The second algorithm improves efficiency by only examining bits that are set to one using bitwise AND and subtraction operations. Both algorithms run in constant time O(1).