Search⌘ K
AI Features

Third Maximum Number

Understand how to determine the third distinct maximum element in an array or return the maximum if fewer than three distinct numbers exist. Explore problem analysis, constraints, and implement a solution using coding patterns covered in the Top K Elements chapter.

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