題目python
class Solution: def findShortestSubArray(self, nums): """ :type nums: List[int] :rtype: int """ counts = collections.Counter(nums) left, right = {}, {} for i, num in enumerate(nums): left.setdefault(num, i) right[num] = i degree = max(counts.values()) res = min(right[num]-left[num]+1 for num in counts.keys() if counts[num] == degree) return res
思路:spa