Leetcode-268 Missing Number
2016-12-16 16:29
197 查看
#268. Missing Number
Given an array containing n distinct numbers taken from
For example,
Given nums =
Note:
Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
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 len=nums.size(); int ret=0; for(int i=0;i<len+1;i++) { ret^=i; } for(int i=0;i<len;i++) { ret^=nums[i]; } return ret; } };
相关文章推荐
- [LeetCode268]Missing Number
- LeetCode 268 Missing Number
- [LeetCode 268] Missing Number
- [LeetCode]268 Missing Number
- leetcode——268——Missing Number
- LeetCode - 268 - Missing Number
- Leetcode 268 Missing Number 位运算
- [leetcode 268]Missing Number
- 【LeetCode】268 Missing Number (java实现)
- LeetCode 268 Missing Number
- Java [Leetcode 268]Missing Number
- <LeetCode OJ>Missing Number【268】
- leetcode_268_Missing Number(Medium)
- 【LeetCode】268 Missing Number
- leetcode 268 Missing Number
- leetcode268:Missing Number
- The Solution to Leetcode 268 Missing Number
- [LeetCode]: 268: Missing Number
- [LeetCode]268 Missing Number
- [leetcode268]Missing Number