forked from hijiangtao/LeetCode-with-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathres.js
More file actions
27 lines (24 loc) · 605 Bytes
/
res.js
File metadata and controls
27 lines (24 loc) · 605 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* 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?
*
* @authors Joe Jiang (hijiangtao@gmail.com)
* @date 2017-02-28 22:47:17
* @version $Id$
*
* @param {number[]} nums
* @return {number}
*/
let singleNumber = function(nums) {
let size = nums.length,
result = 0;
if (!size) {
return null;
}
for (let i=0; i<size; i++) {
result ^= nums[i];
}
return result;
};