解题思路:
(1)使用优先队列排序,依次出队列,取前面的第三大不同数
class Solution {
public:
int thirdMax(vector<int>& nums) {
priority_queue<int> pq;
for (auto w:nums) {
pq.push(w);
}
int max = pq.top(),maxx = pq.top();
int count = 1;
pq.top();
while(!pq.empty()) {
if (max != pq.top()) {
count++;
if (count==3) return pq.top();
max = pq.top();
}
pq.pop();
}
return maxx;
}
};