# Single Number 系列

## 经典题目

### **a .length == n, one appear once and others appear 2 times. Find the one.**

异或消除法：a ^ a = 0

[_136 Single Number_](https://leetcode.com/problems/single-number/description/)

```java
// T/O(n), S/O(1)
public int singleNumber(int[] nums) {
    int ans = 0;
    for (int num : nums) {
        ans ^= num;
    }
    return ans;
}
```

###

### **a.length == n, one appear once and others appear 3 times. Find the one.**&#x20;

[137 &#x53;_&#x69;ngle Number II_](https://leetcode.com/problems/single-number-ii/description/)

```
// T/O(n), S/O(1)

```

###

### **a.length == n, two appear once and others appear 2 times. Find the one.**&#x20;

[_260 Single Number III_](https://leetcode.com/problems/single-number-iii/description/)

```
// T/O(n), S/O(1)

```



