Threadser.net
數據
關鍵字
功能建議
Following
Threads
Login
串文
串文鏈結
2024-11-17 10:31
You’ve got an integer i. Your task: Check if the binary representation of i contains exactly one 1 bit. How would you tackle it?
讚
13
回覆
80
轉發
1
作者
Ramon Sorage
rsorage
粉絲
串文
91+
讚
回覆
轉發
24小時粉絲增長
無資料
互動率
(讚 + 回覆 + 轉發) / 粉絲數
Infinity%
回覆 (BETA)
最先回覆的內容
發文後
用戶
內容
3 小時內
Kevin Maguire
k.c.f.maguire
Then irs a power of 2. Just check it against a list of 1,2,4,…
13 小時內
Everett Richards
everettisaperson
Let W be a row vector corresponding to the binary representation of i. Construct a vertical column vector V of the same length as W, with a 1 in each position. Take the dot product of W and V, and check if it's equal to 1.