Skip to content

Commit 91ef683

Browse files
committed
Add solution #3392
1 parent 7fc55fe commit 91ef683

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@
361361
2490|[Circular Sentence](./2490-circular-sentence.js)|Easy|
362362
2529|[Maximum Count of Positive Integer and Negative Integer](./2529-maximum-count-of-positive-integer-and-negative-integer.js)|Easy|
363363
2535|[Difference Between Element Sum and Digit Sum of an Array](./2535-difference-between-element-sum-and-digit-sum-of-an-array.js)|Easy|
364+
3392|[Count Subarrays of Length Three With a Condition](./3392-count-subarrays-of-length-three-with-a-condition.js)|Easy|
364365
3396|[Minimum Number of Operations to Make Elements in Array Distinct](./3396-minimum-number-of-operations-to-make-elements-in-array-distinct.js)|Easy|
365366
3397|[Maximum Number of Distinct Elements After Operations](./3397-maximum-number-of-distinct-elements-after-operations.js)|Medium|
366367
3402|[Minimum Operations to Make Columns Strictly Increasing](./3402-minimum-operations-to-make-columns-strictly-increasing.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 3392. Count Subarrays of Length Three With a Condition
3+
* https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer array nums, return the number of subarrays of length 3 such that
7+
* the sum of the first and third numbers equals exactly half of the second number.
8+
*/
9+
10+
/**
11+
* @param {number[]} nums
12+
* @return {number}
13+
*/
14+
var countSubarrays = function(nums) {
15+
let count = 0;
16+
for (let i = 0; i < nums.length - 2; i++) {
17+
if (nums[i] + nums[i + 2] === nums[i + 1] / 2) {
18+
count++;
19+
}
20+
}
21+
return count;
22+
};

0 commit comments

Comments
 (0)