diff --git a/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/README.md b/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/README.md index 92850baa30b22..c34d53f3044f1 100644 --- a/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/README.md +++ b/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/README.md @@ -143,6 +143,22 @@ function countSubarrays(nums: number[]): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn count_subarrays(nums: Vec) -> i32 { + let mut ans = 0; + for i in 1..nums.len() - 1 { + if (nums[i - 1] + nums[i + 1]) * 2 == nums[i] { + ans += 1; + } + } + ans + } +} +``` + diff --git a/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/README_EN.md b/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/README_EN.md index 70691ca3f0234..6d3e017f06cd0 100644 --- a/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/README_EN.md +++ b/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/README_EN.md @@ -139,6 +139,22 @@ function countSubarrays(nums: number[]): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn count_subarrays(nums: Vec) -> i32 { + let mut ans = 0; + for i in 1..nums.len() - 1 { + if (nums[i - 1] + nums[i + 1]) * 2 == nums[i] { + ans += 1; + } + } + ans + } +} +``` + diff --git a/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/Solution.rs b/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/Solution.rs new file mode 100644 index 0000000000000..5693e5ff88ff3 --- /dev/null +++ b/solution/3300-3399/3392.Count Subarrays of Length Three With a Condition/Solution.rs @@ -0,0 +1,11 @@ +impl Solution { + pub fn count_subarrays(nums: Vec) -> i32 { + let mut ans = 0; + for i in 1..nums.len() - 1 { + if (nums[i - 1] + nums[i + 1]) * 2 == nums[i] { + ans += 1; + } + } + ans + } +}