Swift solution


  • 0
    class Solution {
        func findComplement(_ num: Int) -> Int {
            var i = 1
            
            while i <= num {
                i <<= 1
            }
            
            return (i - 1) ^ num
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.