C# 1-liner: return ~((~0 << ((int)Math.Floor(Math.Log(num) / Math.Log(2)) + 1)) | num);


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.