Find the Missing Number(寻找缺失的数)

问题

Given an array contains N numbers of 0 .. N, find which number doesn't exist in the array.

Have you met this question in a real interview? Yes
Example
Given N = 3 and the array [0, 1, 3], return 2.

分析

连续异或一个数两次结果不变。所以异或0到n,再异或数组就得到结果。

代码

public class Solution {
    /**    
     * @param nums: an array of integers
     * @return: an integer
     */
    public int findMissing(int[] nums) {
        // write your code here
        int res=0;
        for(int i=0;i

你可能感兴趣的:(Find the Missing Number(寻找缺失的数))