Skip to content

Commit e293e01

Browse files
committed
Add solution #3151
1 parent 228fdac commit e293e01

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@
538538
2948|[Make Lexicographically Smallest Array by Swapping Elements](./2948-make-lexicographically-smallest-array-by-swapping-elements.js)|Medium|
539539
3042|[Count Prefix and Suffix Pairs I](./3042-count-prefix-and-suffix-pairs-i.js)|Easy|
540540
3110|[Score of a String](./3110-score-of-a-string.js)|Easy|
541+
3151|[Special Array I](./3151-special-array-i.js)|Easy|
541542
3223|[Minimum Length of String After Operations](./3223-minimum-length-of-string-after-operations.js)|Medium|
542543
3392|[Count Subarrays of Length Three With a Condition](./3392-count-subarrays-of-length-three-with-a-condition.js)|Easy|
543544
3396|[Minimum Number of Operations to Make Elements in Array Distinct](./3396-minimum-number-of-operations-to-make-elements-in-array-distinct.js)|Easy|

solutions/3151-special-array-i.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 3151. Special Array I
3+
* https://leetcode.com/problems/special-array-i/
4+
* Difficulty: Easy
5+
*
6+
* An array is considered special if every pair of its adjacent elements contains
7+
* two numbers with different parity.
8+
*
9+
* You are given an array of integers nums. Return true if nums is a special array,
10+
* otherwise, return false.
11+
*/
12+
13+
/**
14+
* @param {number[]} nums
15+
* @return {boolean}
16+
*/
17+
var isArraySpecial = function(nums) {
18+
for (let i = 0; i < nums.length - 1; i++) {
19+
if ((nums[i] + nums[i + 1]) % 2 === 0) {
20+
return false;
21+
}
22+
}
23+
return true;
24+
};

0 commit comments

Comments
 (0)