We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a43285c commit 6024eddCopy full SHA for 6024edd
solution/2700-2799/2799.Count Complete Subarrays in an Array/Solution.rs
@@ -1,20 +1,25 @@
1
use std::collections::HashSet;
2
+
3
impl Solution {
4
pub fn count_complete_subarrays(nums: Vec<i32>) -> i32 {
- let mut set: HashSet<&i32> = nums.iter().collect();
5
+ let mut s = HashSet::new();
6
+ for &x in &nums {
7
+ s.insert(x);
8
+ }
9
+ let cnt = s.len();
10
let n = nums.len();
- let m = set.len();
11
let mut ans = 0;
12
13
for i in 0..n {
- set.clear();
14
+ s.clear();
15
for j in i..n {
- set.insert(&nums[j]);
- if set.len() == m {
- ans += n - j;
- break;
16
+ s.insert(nums[j]);
17
+ if s.len() == cnt {
18
+ ans += 1;
19
}
20
21
- ans as i32
22
23
+ ans
24
25
0 commit comments