Majority Element

The array nums has n numbers, and one value appears more than n / 2 times. Return that value.

Constraints

  • 1 ≤ n ≤ 50,000
  • -1,000,000,000 ≤ nums[i] ≤ 1,000,000,000
  • A majority value always exists.

Example 1

Input
nums = [3,2,3]
Output
3
Why:

3 appears twice out of three.

Example 2

Input
nums = [2,2,1,1,1,2,2]
Output
2
Why:

2 appears four times out of seven.

Hints

    Was this a good challenge?

    Solved by
    0
    Submissions
    0
    Accepted
    –