[LintCode] Majority Number

public int majorityNumber(ArrayList<Integer> nums) {
        // write your code
        int index = -1;
        int count = 0;
        for(int i = 0 ; i < nums.size(); i++) {
            if(count == 0) {
                index = i;
                count ++;
            }
            else {
                if(nums.get(i) == nums.get(index))
                    count++;
                else
                    count--;
            }
        }
        return nums.get(index);
    }