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 a linear runtime complexity and use only constant extra space
Example 2
Input: nums = [4,1,2,1,2]
Output: 4
Time Complexity: O(N^2)
Space Complexity: O(1)
Time Complexity: O(N*Log(N))
Space Complexity: O(1)
Time Complexity: O(N)
Space Complexity: O(N)
Time Complexity: O(N)
Space Complexity: O(N)
class Solution:
def singleNumber(self, nums: List[int]) -> int:
ans = nums[0]
for i in range(1, len(nums)):
ans ^= nums[i]
return ans
Time Complexity: O(N)
Space Complexity: O(1)
TODO
Time Complexity: O()
Space Complexity: O()