568.Find the Smallest Element in an Array
Easy
Given an array
nums, return its smallest element.
This is the mirror image of finding the largest element. The scanning version keeps a running minimumRunning MinimumThe smallest value seen so far while walking through a sequence. and updates it whenever something smaller appears; the sorting version is shorter but does far more work than necessary. Starting the running minimum at the first element (not at 0) keeps the answer correct for all-positive arrays.
Example 1:
Input: nums = [12,4,19,7]
Output: 4
Example 2:
Input: nums = [-3,-9,0]
Output: -9
+ 4 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ nums.length ≤ 1000 - ●
-1000000 ≤ nums[i] ≤ 1000000
nums =
[12, 4, 19, 7]