I can't figure out why my code is wrong - anyone see what is wrong?


  • 0
    S
    class Solution(object):
    
    def MSB(self, n ):
        ndx = 0
        while ( 1 < n ):
            n = ( n >> 1 )
            ndx += 1
    
        return ndx
        
    def singleNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        xor = 0
        for item in nums:
            xor ^= item
        
        msb = self.MSB(xor)
        msb_num = int(math.pow(2, msb))
        
        xor_group1 = 0
        xor_group2 = 0
        
        for item in nums:
            if item & msb_num == msb_num:
                xor_group1 ^= item
            else:
                xor_group2 ^= item
                
        return [xor_group1, xor_group2]

Log in to reply
 

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