title | location | images | tags | privacy | createdAt | updatedAt | ||
---|---|---|---|---|---|---|---|---|
Untitled Post |
19.2145, 72.9604 |
|
public |
2025-10-08 13:03:57 UTC |
2025-10-08 13:04:41 UTC |
https://simplecode.co.in/problems/195
#include <vector>
using namespace std;
class Solution {
public:
vector<int> findMaxAndSecondMax(vector<int>& nums) {
int max=INT_MIN;
vector<int> rsl(2,INT_MIN);
for(int i=0;i<nums.size();i++){
if(max<nums[i]){
rsl[1]=max;
max=nums[i];
rsl[0]=max;
}else if (nums[i] > rsl[1] && nums[i] < max){
rsl[1] = nums[i];
}
}
if(rsl[1]==INT_MIN){
rsl[1] = nums[0];
}
return rsl;
}
};