Warm-ups · 8 of 24
Find the missing number from 1 to n
nums holds every number from 1 to n except one, in any order. Return the missing number.
Examples
Input nums = [1, 2, 4, 5], n = 5
Output 3
Input nums = [1, 2, 3], n = 4
Output 4
The missing one can be the last number.
📘 New to this? Indexing and walking through an array explains the idea in a few minutes.
Solved it? The same idea on LeetCode: try it there ↗