![]() |
Given an integer, set the leftmost unset bit. Leftmost unset bit is the first unset bit after most significant set bit. If all bits (after most significant set bit) are set, then return the number. Examples: Input : 10 Output : 14 10 = 1 0 1 0 // 10 binary 14 = 1 1 1 0 // after set left most unset bit Input : 15 Output : 15 15 = 1 1 1 1 // 15 binary 15 = 1 1 1 1 // because all bits are set Approach:- Below is the implementation of the approach. C++
Javascript
Output: 14 Time Complexity: O(log2n) Auxiliary Space: O(1) |
Reffered: https://www.geeksforgeeks.org
Bit Magic |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 19 |