# 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; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up