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

        }
        return major;
    }