public class Solution {
public int majorityElement(int[] num) {
int major=num[0], count = 1;
for(int i=1; i<num.length;i++){
if(count==0){
count++;
major=num[i];
}else if(major==num[i]){
count++;
}else count;
}
return major;
}
}
O(n) time O(1) space fastest solution

got it,It's so good,my solution is like yours, I also used Arrays.sort(nums); but your solution is more Simple and efficient.Here is mine:
public class Solution { public int majorityElement(int[] nums) { Arrays.sort(nums); int maj=0; for(int i=0;i<nums.length/2+1;i++){ if(nums[i]==nums[i+nums.length/2]){ maj=nums[i]; break; } } return maj; } }