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.
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;
@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.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.