# Leetcode 476. Number Complement ###### tags: `Leetcode(C++)` 題目 : https://leetcode.com/problems/number-complement/submissions/ 。 想法 : 找補數,如果剛好是2的指數就輸出其數字-1,否則就輸出2^n-num-1。 時間複雜度 : O(logn)。 程式碼 : ``` class Solution { public: int findComplement(int num) { unsigned int in=1; while(in<=num){ if(in == num){ return in-1; } in*=2; } return in-num-1; } }; ```