Tap here to switch tabs
Problem
Submissions

Problem: Third Maximum Number

Third Maximum Number asks you to return the third distinct maximum value in an integer array, or the overall maximum when fewer than three distinct values exist. Values may be negative.

Statement

Given an integer array, nums, determine and return the third distinct maximum element in the array. If the array contains fewer than three distinct elements, return the maximum element instead.

Constraints:

  • 1<=1 <= nums.length <=103<= 10^3

  • −231<=-2^{31} <=nums[i]<=231−1<= 2^{31}-1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Third Maximum Number

Third Maximum Number asks you to return the third distinct maximum value in an integer array, or the overall maximum when fewer than three distinct values exist. Values may be negative.

Statement

Given an integer array, nums, determine and return the third distinct maximum element in the array. If the array contains fewer than three distinct elements, return the maximum element instead.

Constraints:

  • 1<=1 <= nums.length <=103<= 10^3

  • −231<=-2^{31} <=nums[i]<=231−1<= 2^{31}-1