268. Missing Number
2017-03-26 16:03
155 查看
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.
a^b^b = a
For example,
Given nums = [0, 1, 3] return 2.
a^b^b = a
public class Solution { public int missingNumber(int[] nums) { int res = 0; if (nums == null || nums.length == 0) return res; for (int i = 0; i < nums.length; i++) { res = res ^ i ^ nums[i]; } return res ^ nums.length; } }
相关文章推荐
- LeetCode - 268. Missing Number
- 268. Missing Number
- 268. Missing Number
- 【LeetCode】 268. Missing Number
- 268. Missing Number
- Leetcode--268. Missing Number
- leetcode-java-268. Missing Number
- LeetCode 268. Missing Number - 求和、异或
- 268. Missing Number(查找遗漏的数)
- 268. Missing Number
- 268. Missing Number
- 268. Missing Number
- 268. Missing Number
- leetcode268. Missing Number
- 268. Missing Number
- leetcode 268. Missing Number 解题报告
- 2018.03.15 leetcode 打卡 #268. Missing Number
- LeetCode - 268. Missing Number
- Leetcode-268. Missing Number
- 268. Missing Number(C语言)