写一个函数,该函数是:给出一个数组n的数量,返回多数元素.多数元素是出现超过n / 2次的元素.您可以假设多数元素总是存在于数组中.
Here's an implementation of the function in Python:

```
def majorityElement(nums):
    count = 0
    candidate = None
    
    for num in nums:
        if count == 0:
            candidate = num
        count += (1 if num == candidate else -1)
    
    return candidate
```