• 27.9%

https://leetcode.com/problems/third-maximum-number/

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

https://discuss.leetcode.com/topic/63903/short-easy-c-using-set

Short easy C++ using set

Track the largest three values in a set.

Alternatively (not sure which one I like better):

python

https://discuss.leetcode.com/topic/64696/a-python-amusing-solution-which-actually-beats-98

A python amusing solution, which actually beats 98%…

https://discuss.leetcode.com/topic/70613/intuitive-and-short-python-solution

Intuitive and Short Python solution

Time complexity is O(n), space complexity is O(1).

https://discuss.leetcode.com/topic/63962/python-2-5-lines-o-n-time-o-1-space

Python: 2-5 lines, O(n) time, O(1) space

A slightly shorter but uglier version based on the same concept is:

Although I’m not sure whether the second version is still O(1) space. Does anyone know whether the Python interpreter will create the whole list comprehension in memory even though it is not being assigned anywhere?

Update: two line solution by @StefanPochmann below.

java

https://discuss.leetcode.com/topic/63086/java-priorityqueue-o-n-o-1

Java PriorityQueue O(n) + O(1)

Nice solution, and here is the concise version:

https://discuss.leetcode.com/topic/62236/java-solution-in-0ms-run-time-o-n-and-space-o-1

Java solution in 0ms run time O(n) and space O(1).

https://discuss.leetcode.com/topic/63671/o-n-time-o-1-space-java-short-solution

O(n) time O(1) space Java short solution

https://discuss.leetcode.com/topic/65119/java-solution-using-treeset

Java Solution Using TreeSet