Given an integer array nums, return the third distinct maximum number. If it does not exist, return the maximum number.
Input: An integer array nums.
Output: Integer — the third distinct maximum, or maximum if fewer than 3 distinct values.
Input: [3,2,1]
Output: 1
Explanation: Three distinct values: 3,2,1. Third max = 1.Input: [1,2]
Output: 2
Explanation: Only two distinct values. No third max → return maximum = 2.Input: [2,2,3,1]
Output: 1
Explanation: Distinct values: 1,2,3. Third max = 1.1 <= nums.length <= 10^4-2^31 <= nums[i] <= 2^31-1