//解法二:摩尔投票法 100%classSolution{publicintmajorityElement(int[] nums){int res =0;int votes =0;for(int num : nums){if(votes ==0) res = num;
votes +=(num == res ?1:-1);}return res;}}
//解法三:位运算 30% 慢classSolution{publicintmajorityElement(int[] nums){int result =0, k = nums.length >>1;for(int j =0; j <32; j++){int count =0;for(int num : nums){
count += num >> j &1;if(count > k){
result +=1<< j;break;}}}return result;}}