python bitwise solution


  • 0
    H
    class Solution(object):
        def singleNumber(self, nums):
            """
            :type nums: List[int]
            :rtype: List[int]
            """
            x=0
            for n in nums:
                x^=n
            x&=-x
            ans=[0,0]
            for n in nums:
                ans[int(bool(n&x))]^=n
            return ans
    

Log in to reply
 

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