← 返回 snapchat 的题目列表Shortest Subarray Length with Array's Degree
类型:online_judge
snapchat
Given a non-empty array of integers, find the degree of this array. The degree of an array is the maximum frequency of any one of its elements. Find the smallest possible length of a (contiguous) subarray of the array that has the same degree as the whole array.
Input
An array nums of non-negative integers, with length not exceeding 50,000.
Output
The shortest length of a contiguous subarray with the same degree.
Example
Input:
[1, 2, 2, 3, 1]
Output:
2
Input:
[1, 2, 2, 3, 1, 4, 2]
Output:
6
Example
Input
1,2,2,3,1