<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p>

<p>We call a subarray of an array <strong>complete</strong> if the following condition is satisfied:</p>

<ul>
	<li>The number of <strong>distinct</strong> elements in the subarray is equal to the number of distinct elements in the whole array.</li>
</ul>

<p>Return <em>the number of <strong>complete</strong> subarrays</em>.</p>

<p>A <strong>subarray</strong> is a contiguous non-empty part of an array.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,3,1,2,2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [5,5,5,5]
<strong>Output:</strong> 10
<strong>Explanation:</strong> The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
	<li><code>1 &lt;= nums[i] &lt;= 2000</code></li>
</ul>

from collections import defaultdict

class Solution:
    def countCompleteSubarrays(self, nums: List[int]) -> int:
        need = len(set(nums))  # 整个数组中的不同元素数量
        valid = 0  # 记录结果
        l = 0  # 左指针
        curr = defaultdict(int)  # 当前窗口中每个元素的出现次数
        
        # 遍历右指针
        for r in range(len(nums)):
            # 将右指针指向的元素加入窗口
            curr[nums[r]] += 1
            
            # 当窗口内不同元素的数量等于 need 时
            while len(curr) == need:
                # 符合条件的子数组个数等于从 l 到 r 之间的所有子数组
                valid += len(nums) - r
                
                # 缩小窗口，尝试移除左指针指向的元素
                curr[nums[l]] -= 1
                if curr[nums[l]] == 0:
                    del curr[nums[l]]  # 如果该元素的计数为 0，将其从字典中移除
                l += 1  # 移动左指针
        
        return valid
90