LeetCode: Week 1 — Single Number

Jayram Manale
2 min readApr 13, 2020

--

30-day leet coding challenge

Problem Statement :

Table of Contents:

  1. Code Solution
  2. Explanation
  3. Run Code

Code Solution:

Time Complexity: O(n) | Space Complexity: O(1)

Explanation:

For this problem, we’ll be using Bitwise XOR to get the result. Let's understand how bitwise XOR works

XOR Operation on Binary Values

here, [ A=0, B=0 & A=1, B =1] Both values of bit A and B are equal so it will result in 0and [A=0, B=1 & A=1, B=0] both values of bit A and B are not equal which will result in 1 .

Using this technique, we’ll be finding a unique number in the array. In the XOR operation, the Bitwise method evaluates the binary representation of the given input value. as you can see that below with variable singleNum and nums[i] .

Let's understand the solution code with its execution values for each Iteration.

Execution Values in Each Iteration

Run Code:

You can also check out other problem solution below

I hope you enjoy this solution. Let me know if you have any other solutions in response. Cheers :)

--

--