Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋
times.
You may assume that the array is non-empty and the majority element always exist in the array.
Credits:
Special thanks to for adding this problem and creating all test cases.
这题是简单的一道遍历问题。
#include#include using namespace std;class Solution {public: int majorityElement(vector &num) { int n = num.size(); int cnt = 1; int nowInt = num[0]; for(int i =1;i