Press "Enter" to skip to content

Posts tagged as “index”

花花酱 LeetCode 697. Degree of an Array

题目大意:求”度”相同的最短子数组的长度。

Problem:

https://leetcode.com/problems/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:

Example 2:

Solution 1: Hashtable

Time complexity: O(n)

Space complexity: O(n)

C++