8. Single Number
Given a non-empty array of integers, every element appears twice except for one. Find that single one.
Using Hashmap
Caching
Caching or Indexing is a technique used to store counts of values which lie in a small range.
Time Complexity :O(n) , Space Complexity:O(n)
Using XOR
Concept
If we take XOR of zero and some bit, it will return that bit
a
xor
0 = a⊕0 = a
If we take XOR of two same bits, it will return 0
a
xor
a = a⊕a= 0
a⊕b⊕a = (a⊕a) ⊕ b = 0 ⊕ b = b
Time Complexity :O(n) , Space Complexity:O(1)
Last updated