Let's Connect 🤝 : LinkedIn : www.linkedin.com/in/rochak-vyas17/ Code : class Solution { public: // Function to find the majority elements in the array vector findMajority(vector& nums) { int candidate1=nums[0]; int candidate2=nums[1]; int vote1=0; int vote2=0; int n=nums.size(); vectorans; for(int i=0;in/3){ ans.push_back(candidate2); flag=1; } if(!flag){ return {-1}; } return ans; } };
Let's Connect 🤝 :
LinkedIn : www.linkedin.com/in/rochak-vyas17/
Code :
class Solution {
public:
// Function to find the majority elements in the array
vector findMajority(vector& nums) {
int candidate1=nums[0];
int candidate2=nums[1];
int vote1=0;
int vote2=0;
int n=nums.size();
vectorans;
for(int i=0;in/3){
ans.push_back(candidate2);
flag=1;
}
if(!flag){
return {-1};
}
return ans;
}
};