EbowTang的练习场

1,新手需要努力,高手更需要努力。2,性格大于能力。3，解决问题的能力决定未来。...

<LeetCode OJ> 268. Missing Number

268. Missing Number

Total Accepted: 31740 Total Submissions: 83547 Difficulty: Medium

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.

For example,
Given nums = [0, 1, 3] return 2.

Note:
Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?

class Solution {
public:
int missingNumber(vector<int>& nums) {
int sum = 0;
for(int num: nums)
sum += num;
int n = nums.size();
return (n * (n + 1))/ 2 - sum;
}
};

0 ^ a = a ^ 0 =a
a ^ b = b ^ a
a ^ a = 0
0到size（）间的所有数一起与数组中的数进行异或运算，

class Solution {
public:
int missingNumber(vector<int>& nums) {
int res = 0;
for (int i = 1; i <= nums.size(); i++)
res =res ^ i ^ nums[i-1];
return res;
}
};

268. Missing Number（重要！）

2016-07-13 16:46:58

[leetcode] 268.Missing Number

2015-08-24 10:30:06

268. Missing Number（查找遗漏的数）

2016-11-29 21:14:06

【LeetCode】268 Missing Number （java实现）

2015-08-29 12:28:01

LeetCode 268. Missing Number（缺失数字）

2016-04-11 02:15:40

leetcode 268. Missing Number 缺失数字 python 多种思路，一行代码

2018-06-27 10:50:17

[Leetcode] 268. Missing Number 解题报告

2017-07-05 17:16:46

leetcode：268. Missing Number(Java)解答

2016-03-11 22:07:30

LeetCode268——Missing Number相濡以沫不如相忘于江湖

2015-08-24 21:46:34

leetcode 268. Missing Number-寻找丢失的数|位运算

2016-05-22 21:50:56