# LeetCode 136 Single Number（只出现一次的数字）

## 翻译

给定一个整型数组，除了某个元素外其余元素均出现两次。找出这个只出现一次的元素。

## 原文

Given an array of integers, every element appears twice except for one. Find that single one.

Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

## 代码

class Solution {
public:
unsigned int FindFirstBigIs1(int num) {
int indexBit = 0;
while (((num & 1) == 0) && (indexBit < 8 * sizeof(int))) {
num = num >> 1;
++indexBit;
}
return indexBit;
}

int singleNumber(vector<int>& nums) {
if (nums.size() <= 0) return NULL;

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

unsigned int indexOf1 = FindFirstBigIs1(resultExclusiveOR);

int singleNum = 0;
for (int j = 0; j < nums.size(); ++j) {
singleNum ^= nums[j];
}
return singleNum;
}
};

|
6月前
|

Leetcode 313. Super Ugly Number

66 1
|
6天前
|

【LeetCode力扣】单调栈解决Next Greater Number（下一个更大值）问题
【LeetCode力扣】单调栈解决Next Greater Number（下一个更大值）问题
6 0
|
6月前
|

Leetcode Single Number II （面试题推荐）

22 0
|

LeetCode contest 190 5417. 定长子串中元音的最大数目 Maximum Number of Vowels in a Substring of Given Length
LeetCode contest 190 5417. 定长子串中元音的最大数目 Maximum Number of Vowels in a Substring of Given Length
93 0
|

LeetCode只出现一次的数字使用JavaScript解题|前端学算法
LeetCode只出现一次的数字使用JavaScript解题|前端学算法
112 0
|

110 0
|

106 0
|

88 0
LeetCode Contest 178-1365. 有多少小于当前数字的数字 How Many Numbers Are Smaller Than the Current Number
LeetCode Contest 178-1365. 有多少小于当前数字的数字 How Many Numbers Are Smaller Than the Current Number
67 0
|
6天前
|

【刷题】Leetcode 1609.奇偶树

9 0