[Leetcode] Degree the degree of an array of arrays

Source: Internet
Author: User

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

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

Example 1:

Input: [1, 2, 2, 3, 1]output:2explanation:the input array has a degree of 2 because both elements 1 and 2 appear TWICE.O f The subarrays that has the same degree:[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]the Sho Rtest length is 2. So return 2.

Example 2:

Input: [1,2,2,3,1,4,2]output:6

Note:

    • nums.lengthwould be between 1 and 50,000.
    • nums[i]'ll is an integer between 0 and 49,999.

S

[Leetcode] Degree the degree of an array of arrays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.