Single Number
Easy
Subject: Bit Manipulation
Time Complexity
O(N)
Space Complexity
O(1)
Problem Description
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with linear runtime complexity and constant space.
Optimal Solution
Pythondef singleNumber(nums):
xor = 0
for num in nums:
xor ^= num
return xor