← 返回 bytedance 的题目列表Most Frequent Element with Smallest-Value Tie Break
类型:online_judge
Most Frequent Element with Smallest-Value Tie Break
Given an integer array nums, return the element with the highest frequency.
If multiple elements have the same highest frequency, return the smallest such element.
Input Format
The first line contains an integer n, the array length.
The second line contains n space-separated integers representing nums.
Output Format
Print one integer: the answer.
Constraints
1 <= n <= 2 * 10^5
-10^9 <= nums[i] <= 10^9
Example 1
Input:
6
1 3 2 3 2 1
Output:
1
Explanation: 1, 2, and 3 each occur twice, so return the smallest one, 1.
Example 2
Input:
7
4 4 2 4 2 3 2
Output:
2
Explanation: 2 and 4 each occur three times, so return the smaller value, 2.
Example
Input
6
1 3 2 3 2 1
Output
1