Skip to content

Commit 361baa7

Browse files
authored
Create 2799. Count Complete Subarrays in an Array (#776)
2 parents ab3ceb5 + b29db49 commit 361baa7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
int countCompleteSubarrays(vector<int>& nums) {
4+
unordered_map<int, int> m, m1;
5+
for(int ele : nums) m[ele]++;
6+
int n = nums.size();
7+
int distinct = m.size(); // total distinct elements in nums
8+
int cnt = 0;
9+
10+
for(int i = 0; i < n; i++) {
11+
for(int j = i; j < n; j++) {
12+
m1[nums[j]]++;
13+
if(m1.size() == distinct) cnt++;
14+
}
15+
m1.clear();
16+
}
17+
18+
return cnt;
19+
}
20+
};

0 commit comments

Comments
 (0)