Skip to content

Commit 9f9a2ad

Browse files
committed
Sync LeetCode submission Runtime - 3 ms (23.22%), Memory - 18 MB (12.54%)
1 parent 33c2d09 commit 9f9a2ad

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

3429-special-array-i/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<p>An array is considered <strong>special</strong> if every pair of its adjacent elements contains two numbers with different parity.<!-- notionvc: e6bed0fa-c67d-43a7-81b4-99fb85b99e98 --></p>
2+
3+
<p>You are given an array of integers <code>nums</code>. Return <code>true</code> if <code>nums</code> is a <strong>special</strong> array, otherwise, return <code>false</code>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
8+
<div class="example-block">
9+
<p><strong>Input:</strong> <span class="example-io">nums = [1]</span></p>
10+
11+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
12+
13+
<p><strong>Explanation:</strong></p>
14+
15+
<p>There is only one element. So the answer is <code>true</code>.</p>
16+
</div>
17+
18+
<p><strong class="example">Example 2:</strong></p>
19+
20+
<div class="example-block">
21+
<p><strong>Input:</strong> <span class="example-io">nums = [2,1,4]</span></p>
22+
23+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
24+
25+
<p><strong>Explanation:</strong></p>
26+
27+
<p>There is only two pairs: <code>(2,1)</code> and <code>(1,4)</code>, and both of them contain numbers with different parity. So the answer is <code>true</code>.</p>
28+
</div>
29+
30+
<p><strong class="example">Example 3:</strong></p>
31+
32+
<div class="example-block">
33+
<p><strong>Input:</strong> <span class="example-io">nums = [4,3,1,6]</span></p>
34+
35+
<p><strong>Output:</strong> <span class="example-io">false</span></p>
36+
37+
<p><strong>Explanation:</strong></p>
38+
39+
<p><code>nums[1]</code> and <code>nums[2]</code> are both odd. So the answer is <code>false</code>.</p>
40+
</div>
41+
42+
<p>&nbsp;</p>
43+
<p><strong>Constraints:</strong></p>
44+
45+
<ul>
46+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
47+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
48+
</ul>

3429-special-array-i/solution.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Approach: Linear Scan
2+
3+
# Time: O(n)
4+
# Space: O(1)
5+
6+
class Solution:
7+
def isArraySpecial(self, nums: List[int]) -> bool:
8+
for i in range(len(nums) - 1):
9+
if (nums[i] % 2) == (nums[i + 1] % 2):
10+
return False
11+
12+
return True
13+

0 commit comments

Comments
 (0)