Leetcode 697 - Degree of an Array

Note:

• First iteration to get max frequency and every n‘s indexes.
• For n whose indexes === max, use val[len - 1] - val[0] + 1 to get the length, and find the min length.

Question:

Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.

Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.

Example:

Code: