葉林
Linked with GitHub
# LeetCode - 0476. Number Complement ### 題目網址:https://leetcode.com/problems/number-complement/ ###### tags: `LeetCode` `Easy` `位元運算` `位元遮罩(Bit Mask)` ```cpp= /* -LeetCode format- Problem: 476. Number Complement Difficulty: Easy by Inversionpeter */ class Solution { public: int findComplement(int num) { unsigned leftMost = 1 << 31; while (leftMost) { if (leftMost & num) break; leftMost >>= 1; } return (~num) & (leftMost - 1); } }; ```
×
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