Bit-Manipulation
LeetCode 405: Convert a Number to Hexadecimal
·1 分鐘
LeetCode
Easy
Math
String
Bit-Manipulation
LeetCode 405 解題筆記:負數先加上 2^32 變成補數,再每次取 4 個位元(% 16)轉成十六進位;0 要特別處理
LeetCode 389: Find the Difference
·1 分鐘
LeetCode
Easy
Hash-Table
String
Bit-Manipulation
Sorting
LeetCode 389 解題筆記:t 比 s 多一個字元,把兩個字串的所有字元 XOR 起來,成對的抵消,剩下的就是多的那個
LeetCode 342: Power of Four
·1 分鐘
LeetCode
Easy
Math
Bit-Manipulation
Recursion
LeetCode 342 解題筆記:先確認是 2 的次方,再確認那個 1 在偶數位:n & 0x55555555 != 0,或 n % 3 == 1
LeetCode 231: Power of Two
·1 分鐘
LeetCode
Easy
Math
Bit-Manipulation
Recursion
LeetCode 231 解題筆記:2 的次方只有一個位元是 1,n & (n - 1) 會把最低的 1 消掉,結果是 0 就是;n 要是正數
LeetCode 136: Single Number
·1 分鐘
LeetCode
Easy
Array
Bit-Manipulation
LeetCode 136 解題筆記:x ^ x = 0、x ^ 0 = x,把所有數 XOR 起來,出現兩次的互相抵消,剩下的就是答案
LeetCode 67: Add Binary
·1 分鐘
LeetCode
Easy
Math
String
Bit-Manipulation
Simulation
LeetCode 67 解題筆記:從兩個字串的尾巴往前逐位相加,進位是 sum // 2,這一位是 sum % 2