Java one line solution


  • 1
    U

    Iterating from 0 to nums.length, and reducing all the elements and its index with xor operation.

    public int missingNumber(int[] nums) {
            return IntStream.range(0, nums.length).reduce(nums.length, (result, i) -> result = result^i^nums[i]);
        }
    

Log in to reply
 

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