Majority Element
Problem
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:
Pseudocode
Solution
Time and Space Complexity
Time
Loop through array once to find unique numbers and their counts - O(N)
Total - O(N)
Space
Storing a map of unique numbers and their counts - O(N)
Total - O(N)
Last updated