> For the complete documentation index, see [llms.txt](https://coding-9.gitbook.io/untitled/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coding-9.gitbook.io/untitled/array/easy/136.-single-number.md).

# 136. Single Number

## Problem Statement

<br>

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.

&#x20;

**Example 1:**

<pre><code><strong>Input: nums = [2,2,1]
</strong><strong>Output: 1
</strong></code></pre>

**Example 2:**

<pre><code><strong>Input: nums = [4,1,2,1,2]
</strong><strong>Output: 4
</strong></code></pre>

**Example 3:**

<pre><code><strong>Input: nums = [1]
</strong><strong>Output: 1
</strong></code></pre>

&#x20;

**Constraints:**

* `1 <= nums.length <= 3 * 104`
* `-3 * 104 <= nums[i] <= 3 * 104`
* Each element in the array appears twice except for one element which appears only once.

<br>

## Intuition

```
We can use exor operation ; 
This works because all elements are twice and in exor 1^1=0 and 2^2=0
So on , all elements twice are nullified and only one remains
```

### Links

<https://leetcode.com/problems/single-number/>

### Video Links

### Approach 1:

```
Xor
```

{% code title="C++" lineNumbers="true" %}

```cpp
class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int f=0;

        for(int i=0;i<nums.size();i++){
            f^=nums[i];
        }

        return f;
    }
};
```

{% endcode %}

### Approach 2:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Approach 3:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Approach 4:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Similar Problems

###
