您的位置:首页 > 其它

169 Majority Element

2014-12-25 08:42 295 查看
public class Solution {

public int majorityElement(int[] num) {

System.out.println(num.length);

int major = num[0];

int count = 1;

for(int i = 1;i < num.length ; i++){

if(num[i] == major){

count++;

}else{

count--;

if(count == 0){

if(i+1 < num.length){

major = num[i+1];

count=1;

i++;

}

}

}

}

return major;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: