3392. Count Subarrays of Length Three With a Condition Easy
1/**
2 * [3392] Count Subarrays of Length Three With a Condition
3 *
4 * Given an integer array nums, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of length 3 such that the sum of the first and third numbers equals exactly half of the second number.
5 *
6 * <strong class="example">Example 1:
7 * <div class="example-block">
8 * Input: <span class="example-io">nums = [1,2,1,4,1]</span>
9 * Output: <span class="example-io">1</span>
10 * Explanation:
11 * Only the subarray [1,4,1] contains exactly 3 elements where the sum of the first and third numbers equals half the middle number.
12 * </div>
13 * <strong class="example">Example 2:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [1,1,1]</span>
16 * Output: <span class="example-io">0</span>
17 * Explanation:
18 * [1,1,1] is the only subarray of length 3. However, its first and third numbers do not add to half the middle number.
19 * </div>
20 *
21 * Constraints:
22 *
23 * 3 <= nums.length <= 100
24 * <font face="monospace">-100 <= nums[i] <= 100</font>
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/
30// discuss: https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn count_subarrays(nums: Vec<i32>) -> i32 {
36 0
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_3392() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.