写一个解决这个问题的函数:给出一个数组n的数量,返回多数元素.多数元素是出现超过n / 2次的元素.您可以假设多数元素总是存在于数组中.
Here's a possible implementation in Python:

```
def majorityElement(nums):
    counts = {}
    for num in nums:
        if num in counts:
            counts[num] += 1
        else:
            counts[num] = 1
        if counts[num] > len(nums) // 2:
            return num
```

This function uses a dictionary to keep track of the counts of each element in the input array. It iterates over the array, updating the counts for each element and checking if any element has already appeared more than half the length of the array. If so, it immediately returns that element as the majority element. Since the prompt states that the majority element always exists in the array, we do not need to handle the case where no element appears more than half the length of the array.