Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How leetcode returns a subarray of K different integers

Shulou Source: shulou.com Published: 2022-06-01 12:47:19 11月12日 Update

This article will explain in detail how leetcode returns a subarray of K different integers. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Given a positive integer array A, if the number of different integers in a subarray of A happens to be K, the continuous and not necessarily independent subarray of An is called a good subarray.

(for example, there are three different integers in [1Pert 2, 3pr 1], and 3. )

Returns the number of good subarrays in A.

Example 1:

Output: a = [1, 2, 2, 1, 1, 2, 3], K = 2

Enter: 7

Explanation: a subarray that happens to be composed of two different integers: [1], [2], [1], [2], [2], [2], [2].

Example 2:

Input: a = [1, 2, 1, 3, 4], K = 3

Output: 3

Explanation: a subarray of exactly three different integers: [1], [2], [3], [3].

Tip:

one

Tags: Arrays different integers pointers articles moves two number more examples questions topics explanations input output good practical size content ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Linux macOS Shulou Information Docker