Find Largest Element in an Array
Implement findLargest
Given an array of integers
nums, find and return the largest element in the array.
You may assume the array contains at least one element. Solve it with a single passSingle PassVisiting each element of the array exactly once, without sorting or scanning the array more than one time. through the array — no sorting required.
Example 1:
Input: nums = [3,7,2,9,4]
Output: 9
Example 2:
Input: nums = [1,1,1]
Output: 1
Example 3:
Input: nums = [-5,-2,-9,-1]
Output: -1
+ 9 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ nums.length ≤ 10⁵ - ●
-10⁹ ≤ nums[i] ≤ 10⁹
nums =
[3, 7, 2, 9, 4]