# [LeetCode] 136. Single Number

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.

Example 1:

Input: nums = [2,2,1]
Output: 1
Example 2:

Input: nums = [4,1,2,1,2]
Output: 4
Example 3:

Input: nums = 
Output: 1

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.

## 代码

``````class Solution {
public int singleNumber(int[] nums) {
int single = 0;
for (int num : nums) {
single ^= num;
}
return single;
}
}
``````

### 推荐这些文章：

LeetCode 1056. Confusing Number

Given a number N, return true if and only if it is a confusing number, which satisfies th...

[leetcode] 136. Single Number

Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).
Note:

Note that in some languages, such...

LeetCode 0065 Valid Number

1. 题目描述

2. Solution 1
1、思路分析
All we need is to have a couple of flags so we can process the string in liner time:
If we see [0-9] we rese...

LeetCode 912. Sort an Array

Given an array of integers nums, sort the array in ascending order.
Example 1:
Input: nums = [5,2,3,1]
Outp...

LeetCode 0078 Subsets

1. 题目描述

2. Solution 1
**1、思路分析 **

2、代码实现
package Q0099.Q0078Subsets;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
impor...

[leetcode] 202. Happy Number

Write an algorithm to determine if a number n is happy.
A happy number is a number defined by the following process:

Starting with any positive integer, replace the ...

LeetCode 796. Rotate String

We are given two strings, A and B.
A shift on A consists of taking string A&n...

LeetCode 0075 Sort Colors

1. 题目描述

2. Solution 1
1、思路分析

2、代码实现
package Q0099.Q0075SortColors;

public class Solution {
/*
The idea is to ...

LeetCode 390. Elimination Game

There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and...

540. Single Element in a Sorted Array

THE END