A 3-line Ruby O(1), O(n) solution


  • 0
    A
    # @param {Integer[]} nums
    # @return {Integer}
    def missing_number(nums)
        a = (nums.size + 1).times.reduce(:^)
        b = nums.reduce(:^)
        a ^ b
    end

Log in to reply
 

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