169. Majority Element
Practice Majority Element for free on NudgeCode: Easy, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Return the value that appears more than n / 2 times in nums, where n is the length of the array. Such a value is guaranteed to exist. Try for O(n) time and O(1) extra space.
Example
nums = [2,2,1,1,1,2,2] -> 2
Constraints
- 1 <= nums.length <= 5 * 10^4
- -10^9 <= nums[i] <= 10^9