Majority Element
Last updated
Last updated
Given an array
nums
of sizen
, return the majority element.The majority element is the element that appears more than
⌊n / 2⌋
times. You may assume that the majority element always exists in the array.
Example 1:
Example 2:
Loop through array once to find unique numbers and their counts - O(N)
Total - O(N)
Storing a map of unique numbers and their counts - O(N)
Total - O(N)