You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for(int i = 1; i < num + 1; i++) ans[i] = ans[i & (i - 1)] + 1;
return ans;
}
}
/*
In order to remove the least-significant bit for any number “n” just take its “and(&)” with “n - 1”.
Now since the numbers “n” and “( n & ( n - 1 ) )” differs only by one bit, we can use the result obtained for “( n & ( n - 1 ) )” and add one to it to obtain the result for “n”.