EasyBit Manipulation
Single Number
Find single number in array
Solution Approach
Use XOR operation. XOR of two same numbers is 0, XOR of any number with 0 is itself.
Implementation
def singleNumber(nums):
result = 0
for num in nums:
result ^= num
return resultComplexity Analysis
Time Complexity
O(n)Space Complexity
O(1)Complexity
Time:O(n)
Space:O(1)
Asked at
GoogleAmazonMicrosoft