19. Find first set bit
My Approach
Bruteforce Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution
{
public:
unsigned int getFirstSetBit(int n)
{
int cnt = 0;
while(n){
cnt++;
if(n&1)
break;
n >>= 1;
}
return cnt;
}
};Optimized Approach
Time and Auxiliary Space Complexity
Code (C++)
Contribution and Support
Last updated