Leetcode 414. 第三大的数 腾讯校招面试题(一次遍历,最大值,次大值,此次大值必须同时更新)
作者:互联网
class Solution {
public:
int thirdMax(vector<int>& nums) {
long a = LONG_MIN, b = LONG_MIN, c = LONG_MIN;
for (auto num : nums) {
if (num > a) {
c = b;
b = a;
a = num;
} else if (a > num && num > b) {
c = b;
b = num;
} else if (b > num && num > c) {
c = num;
}
}
return c == LONG_MIN ? a : c;
}
};
标签:面试题,num,MIN,nums,LONG,else,414,次大值,&& 来源: https://blog.csdn.net/wwxy1995/article/details/120851294