Java Solution, No XOR, Very easy to understand


  • 0
    T
    public int missingNumber(int[] nums) {
            if(nums.length==0) return 0;
            int total = 0;
            int real = 0;
            for(int i =0; i<nums.length;i++){
                total+=i;
                real+=nums[i];
            }
            total+=nums.length;
            return (total-real);
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.