268_Missing Number
Last updated
Last updated
[Easy][Array, Math, Bit Manipulation]
Given an array containing n distinct numbers taken from0, 1, 2, ..., n
, find the one that is missing from the array.
Example 1:
Example 2:
Idea:
Sort the array in ascending order.
Loop over each element, find which element doesn't equal to it's index.
Time Complexity:
Space Complexity:
Idea:
Use math summation formula.
Loop over each element in the array to get the summation. The difference between the expected summation and real summation will be the element missing.
If there is no element missing, adding from 0 to n gives .
Time Complexity:
Space Complexity: