Skip to content

Commit 6024edd

Browse files
authored
Update Solution.rs
1 parent a43285c commit 6024edd

File tree

1 file changed

+13
-8
lines changed
  • solution/2700-2799/2799.Count Complete Subarrays in an Array

1 file changed

+13
-8
lines changed
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
use std::collections::HashSet;
2+
23
impl Solution {
34
pub fn count_complete_subarrays(nums: Vec<i32>) -> i32 {
4-
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();
510
let n = nums.len();
6-
let m = set.len();
711
let mut ans = 0;
12+
813
for i in 0..n {
9-
set.clear();
14+
s.clear();
1015
for j in i..n {
11-
set.insert(&nums[j]);
12-
if set.len() == m {
13-
ans += n - j;
14-
break;
16+
s.insert(nums[j]);
17+
if s.len() == cnt {
18+
ans += 1;
1519
}
1620
}
1721
}
18-
ans as i32
22+
23+
ans
1924
}
2025
}

0 commit comments

Comments
 (0)