414. Third Maximum Number
π© Easy
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).
Example 1:
Example 2:
Example 3:
One Pass Approach
first > second > third. Shift the value for each in every iteration
Time complexity: O(n)
Space complexity: O(1)
Sort Approach (Not satisfy time complexity requirement)
Time complexity: O(n log n)
Space complexity: O(1)
Last updated
Was this helpful?