5. Find the Largest Number
EasyArrays~6 min
Given an array of numbers, return the largest one.
If the array is empty, return null.
Examples
Example 1
- Input:
- numbers = [3, 7, 2, 9, 4]
- Output:
- 9
Example 2
- Input:
- numbers = [-5, -2, -9]
- Output:
- -2
- Why:
- -2 is the closest to zero, so it is the largest.
Example 3
- Input:
- numbers = []
- Output:
- null
Constraints
0 <= numbers.length <= 1000-10000 <= numbers[i] <= 10000