You get a Vec of integers nums. Return its smallest and its largest number together, as a pair.
The smallest number comes first. The function's return type shows how your language holds the pair.
Find both in one loop. Don't use a built-in min or max function.
Example 1:
Input: nums = [4, -2, 9, 0] Output: (-2, 9) Explanation: The smallest number is -2. The largest number is 9.
Example 2:
Input: nums = [7] Output: (7, 7) Explanation: The only number is both the smallest and the largest.
Example 3:
Input: nums = [-5, -1, -8] Output: (-8, -1) Explanation: All the numbers are below 0. The smallest is -8, and the largest is -1.
Constraints:
numshas at least one number.- Every number is between -106 and 106.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
