Search⌘ K
AI Features

Solution: Third Maximum Number

Explore how to identify the third distinct maximum number in an integer array by using a min heap and set to track top elements. Understand how to handle duplicates and arrays with fewer than three distinct numbers, and learn the time and space complexity analysis of this solution.

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 <= ...