Leetcode 414 Solution
This article provides solution to leetcode question 414 (third-maximum-number)
Access this page by simply typing in "lcs 414" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/third-maximum-number
Solution
class Solution {
public:
int thirdMax(vector<int>& nums) {
long m1 = LONG_MIN;
long m2 = LONG_MIN;
long m3 = LONG_MIN;
for (auto num : nums)
{
if (num > m1)
{
m3 = m2;
m2 = m1;
m1 = num;
}
else if (num == m1)
continue;
else if (num > m2)
{
m3 = m2;
m2 = num;
}
else if (num == m2)
continue;
else if (num > m3)
m3 = num;
}
return m3 == LONG_MIN ? m1 : m3;
}
};