# Leetcode 1009. Complement of Base 10 Integer ###### tags: `Leetcode(C++)` 題目 : https://leetcode.com/problems/complement-of-base-10-integer/ 。 想法 : 按照題目敘述操作,將0轉1,將1轉0。 時間複雜度 : O(logn)。 程式碼 : ``` class Solution { public: int bitwiseComplement(int n) { if(n == 0) return 1; int num = 1; while(num < n){ num *= 2; } if(num == n) return n - 1; return num - 1 - n; } }; ```