# Majority Number

题目：

Given an array of integers, the majority number is the number that occurs more than half of the size of the array. Find it.

分析：

扔掉俩不一样的数，剩下的数就是主元素

解法：

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nataliekung.gitbook.io/ladder_code/high-frequency/majority-number.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
