数组中的数字出现次数超过一半

public class Solution {
    public int MoreThanHalfNum_Solution(int [] array) {
        int key = 0;
        int number = 0;
        for(int i = 0;i<array.length;i++){
            if(number==0){
                key = array[i];
                number = 1;
            }else{
                if(key == array[i]){
                    number++;
                }else{
                    number--;
                }
            }
        }
        return key;
    }
}