Swift | One-liner explained
Approach\n~num inverts all bits in num\nFor example, 5 which is 00000000000000000000000000000|101 in binary, becomes 11111111111111111111111111111|010 \n\nTo ge
# Approach\n`~num` inverts all bits in `num`\nFor example, `5` which is `00000000000000000000000000000|101` in binary, becomes `11111111111111111111111111111|010` \n\nTo get rid of these leading `1`-s we first bitshift this number to the left by `num.leadingZeroBitCount` postions, getting `010|00000000000000000000000000000`, then back right by the same number, obtaining the desired result `00000000000000000000000000000|010`\n\n# Complexity\n- Time complexity: $O(1)$\n- Space complexity: $O(1)$\n\n# Code\n```swift []\nclass Solution {\n    func findComplement(_ num: Int) -> Int {\n        (~num << num.leadingZeroBitCount) >> num.leadingZeroBitCount\n    }\n}\n```
['Bit Manipulation', 'Swift']