Skip to content

Instantly share code, notes, and snippets.

@Josephchinedu
Last active September 16, 2022 08:42
Show Gist options
  • Save Josephchinedu/63b7aad1a7b427db060823c69bc37485 to your computer and use it in GitHub Desktop.
Save Josephchinedu/63b7aad1a7b427db060823c69bc37485 to your computer and use it in GitHub Desktop.
Description:
Given a non-empty array of integers, every element appears twice except one, find it
Steps:
1. Find the sum of the array
2. Find a unique element in the array
3. Find the sum of the unique element
4. Multiply the sum of the unique element by 2
5. then minus sum of the array from the result of step 4
Time complexity O(N):
We pass over the input array.
We do a separate over the set ones
space Complexity O(N)
Due to the usage of a set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment