Skip to content

Commit 186aa5e

Browse files
authored
feat: add rust solution to lc problem: No.3392 (#4375)
No.3392.Count Subarrays of Length Three With a Condition
1 parent 7db519a commit 186aa5e

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ function countSubarrays(nums: number[]): number {
143143
}
144144
```
145145

146+
#### Rust
147+
148+
```rust
149+
impl Solution {
150+
pub fn count_subarrays(nums: Vec<i32>) -> i32 {
151+
let mut ans = 0;
152+
for i in 1..nums.len() - 1 {
153+
if (nums[i - 1] + nums[i + 1]) * 2 == nums[i] {
154+
ans += 1;
155+
}
156+
}
157+
ans
158+
}
159+
}
160+
```
161+
146162
<!-- tabs:end -->
147163

148164
<!-- solution:end -->

solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/README_EN.md

+16
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ function countSubarrays(nums: number[]): number {
139139
}
140140
```
141141

142+
#### Rust
143+
144+
```rust
145+
impl Solution {
146+
pub fn count_subarrays(nums: Vec<i32>) -> i32 {
147+
let mut ans = 0;
148+
for i in 1..nums.len() - 1 {
149+
if (nums[i - 1] + nums[i + 1]) * 2 == nums[i] {
150+
ans += 1;
151+
}
152+
}
153+
ans
154+
}
155+
}
156+
```
157+
142158
<!-- tabs:end -->
143159

144160
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
impl Solution {
2+
pub fn count_subarrays(nums: Vec<i32>) -> i32 {
3+
let mut ans = 0;
4+
for i in 1..nums.len() - 1 {
5+
if (nums[i - 1] + nums[i + 1]) * 2 == nums[i] {
6+
ans += 1;
7+
}
8+
}
9+
ans
10+
}
11+
}

0 commit comments

Comments
 (0)