414. Third Maximum Number
c++ STL
set容器
insert后的set是从小到大排序的。
set.begin() < .. < set.rbegin()
参考代码:
class Solution { public: int thirdMax(vector<int>& nums) { set<int> MaxSet; for(int i=0; i<nums.size(); i++){ MaxSet.insert(nums[i]); if(MaxSet.size()>3) MaxSet.erase(MaxSet.begin()); } if(MaxSet.size()==3) return *MaxSet.begin(); else return *MaxSet.rbegin(); } };
相关推荐
MrFuWen 2020-06-25
丽丽 2020-06-08
容数据服务集结号 2020-06-08
chengjian0 2020-05-17
somyjun 2020-05-12
willluckysmile 2020-05-03
akcsdno 2020-04-23
shenxiuwen 2020-04-15
akcsdno 2020-03-06
kong000dao0 2020-03-04
CoderBoy 2020-03-03
MrFuWen 2020-02-22
vipiter 2020-02-14
CoderBoy 2020-01-18
JayFighting 2019-12-16
akcsdno 2019-12-13
宿舍 2019-10-24
JayFighting 2019-10-21