697. Degree of an Array
Description
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 1:
1 | Input: nums = [1,2,2,3,1] |
Example 2:
1 | Input: nums = [1,2,2,3,1,4,2] |
Constraints:
nums.lengthwill be between 1 and 50,000.nums[i]will be an integer between 0 and 49,999.
Hints/Notes
- 2025/03/27 Q3
- map
- Leetcode solution
Solution
Language: C++
1 | class Solution { |