Third Maximum Number
Easy
Arrays
Array
Sorting
Given an integer array, return the third distinct maximum. If fewer than 3 distinct, return the max.
Constraints
1 ≤ nums.length ≤ 10^4
Examples
Example 1:
Input: 3 2 1
Output: 1
Example 2:
Input: 1 2
Output: 2
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console