diff --git a/LEETCODE SOLUTIONS/229_Majority_Element_II.cpp b/LEETCODE SOLUTIONS/229_Majority_Element_II.cpp new file mode 100644 index 0000000..39412df --- /dev/null +++ b/LEETCODE SOLUTIONS/229_Majority_Element_II.cpp @@ -0,0 +1,23 @@ +class Solution { +public: + vector majorityElement(vector& nums) { + vector ans; + int n=nums.size(); + int count=1; + sort(nums.begin(),nums.end()); + for(int i=1;in/3) + ans.push_back(nums[i-1]); + count=1; + } + } + if(count>n/3) + ans.push_back(nums[n-1]); + return ans; + } +};