I only want to say: this problem is not Medium,it is Hard!


  • 29
    B

    What a strange brain can get the solution!:)


  • 0
    A

    yeah, if you haven't played around with the problem and encounter it for the first time in interview, its kind of hard to come up with this solution in 30 minutes.


  • -11
    Z
    class Solution(object):
        def singleNumber(self, nums):
            """
            :type nums: List[int]
            :rtype: List[int]
            """
            a=0;
            b=0;
            d=0;
            nums.sort();
            x=0;
            while x<len(nums):
                if nums[x]!=nums[x+1]:
                    a=nums[x];
                    break;
                else:
                    x=x+2;
            for c in range(0,len(nums)):
                b=b^nums[c];
            d=b^a;
            list=[a,d];
            return list;
    

  • 0
    D

    @Beluma I admit that if you see problem backward when you know the solution, then you will say: oh, of course we should care about that there must exist one bit that appears odd number of times!

    But you simply don't know the above statement when you see the problem forward.


Log in to reply
 

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