LeetCode: Missing Number
Question
Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.
Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity?
Solution
def missing_number(nums)
n = nums.size
((0..n).to_a - nums).first
end
Comments