From f56807d21ced13a218818220b75757f053c94c88 Mon Sep 17 00:00:00 2001 From: nathannaveen <42319948+nathannaveen@users.noreply.github.com> Date: Sun, 19 May 2024 20:20:18 +0000 Subject: [PATCH] Sync LeetCode submission Runtime - 0 ms (100.00%), Memory - 3 MB (100.00%) --- 3429-special-array-i/README.md | 48 ++++++++++++++++++++++++++++++++ 3429-special-array-i/solution.go | 12 ++++++++ 2 files changed, 60 insertions(+) create mode 100644 3429-special-array-i/README.md create mode 100644 3429-special-array-i/solution.go diff --git a/3429-special-array-i/README.md b/3429-special-array-i/README.md new file mode 100644 index 0000000..c540d7d --- /dev/null +++ b/3429-special-array-i/README.md @@ -0,0 +1,48 @@ +

An array is considered special if every pair of its adjacent elements contains two numbers with different parity.

+ +

You are given an array of integers nums. Return true if nums is a special array, otherwise, return false.

+ +

 

+

Example 1:

+ +
+

Input: nums = [1]

+ +

Output: true

+ +

Explanation:

+ +

There is only one element. So the answer is true.

+
+ +

Example 2:

+ +
+

Input: nums = [2,1,4]

+ +

Output: true

+ +

Explanation:

+ +

There is only two pairs: (2,1) and (1,4), and both of them contain numbers with different parity. So the answer is true.

+
+ +

Example 3:

+ +
+

Input: nums = [4,3,1,6]

+ +

Output: false

+ +

Explanation:

+ +

nums[1] and nums[2] are both odd. So the answer is false.

+
+ +

 

+

Constraints:

+ + diff --git a/3429-special-array-i/solution.go b/3429-special-array-i/solution.go new file mode 100644 index 0000000..8255127 --- /dev/null +++ b/3429-special-array-i/solution.go @@ -0,0 +1,12 @@ +func isArraySpecial(nums []int) bool { + prev := -1 + + for _, n := range nums { + if prev != -1 && n % 2 == prev % 2 { + return false + } + prev = n + } + + return true +}