Skip to content

Commit edb7ba7

Browse files
authored
feat: add weekly contest 398 (doocs#2837)
1 parent 5f60e89 commit edb7ba7

File tree

13 files changed

+913
-1
lines changed

13 files changed

+913
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3151.Special%20Array%20I/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3151. 特殊数组 I](https://leetcode.cn/problems/special-array-i)
10+
11+
[English Version](/solution/3100-3199/3151.Special%20Array%20I/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>如果数组的每一对相邻元素都是两个奇偶性不同的数字,则该数组被认为是一个 <strong>特殊数组</strong> 。</p>
18+
19+
<p>Aging 有一个整数数组 <code>nums</code>。如果 <code>nums</code> 是一个 <strong>特殊数组</strong> ,返回 <code>true</code>,否则返回 <code>false</code>。</p>
20+
21+
<p>&nbsp;</p>
22+
23+
<p><strong class="example">示例 1:</strong></p>
24+
25+
<div class="example-block">
26+
<p><strong>输入:</strong><span class="example-io">nums = [1]</span></p>
27+
28+
<p><strong>输出:</strong><span class="example-io">true</span></p>
29+
30+
<p><strong>解释:</strong></p>
31+
32+
<p>只有一个元素,所以答案为 <code>true</code>。</p>
33+
</div>
34+
35+
<p><strong class="example">示例 2:</strong></p>
36+
37+
<div class="example-block">
38+
<p><strong>输入:</strong><span class="example-io">nums = [2,1,4]</span></p>
39+
40+
<p><strong>输出:</strong><span class="example-io">true</span></p>
41+
42+
<p><strong>解释:</strong></p>
43+
44+
<p>只有两对相邻元素: <code>(2,1)</code> 和 <code>(1,4)</code>,它们都包含了奇偶性不同的数字,因此答案为 <code>true</code>。</p>
45+
</div>
46+
47+
<p><strong class="example">示例 3:</strong></p>
48+
49+
<div class="example-block">
50+
<p><strong>输入:</strong><span class="example-io">nums = [4,3,1,6]</span></p>
51+
52+
<p><strong>输出:</strong><span class="example-io">false</span></p>
53+
54+
<p><strong>解释:</strong></p>
55+
56+
<p><code>nums[1]</code> 和 <code>nums[2]</code> 都是奇数。因此答案为 <code>false</code>。</p>
57+
</div>
58+
59+
<p>&nbsp;</p>
60+
61+
<p><strong>提示:</strong></p>
62+
63+
<ul>
64+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
65+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
66+
</ul>
67+
68+
<!-- description:end -->
69+
70+
## 解法
71+
72+
<!-- solution:start -->
73+
74+
### 方法一
75+
76+
<!-- tabs:start -->
77+
78+
#### Python3
79+
80+
```python
81+
82+
```
83+
84+
#### Java
85+
86+
```java
87+
88+
```
89+
90+
#### C++
91+
92+
```cpp
93+
94+
```
95+
96+
#### Go
97+
98+
```go
99+
100+
```
101+
102+
<!-- tabs:end -->
103+
104+
<!-- solution:end -->
105+
106+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3151.Special%20Array%20I/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3151. Special Array I](https://leetcode.com/problems/special-array-i)
10+
11+
[中文文档](/solution/3100-3199/3151.Special%20Array%20I/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<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>
18+
19+
<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>
20+
21+
<p>&nbsp;</p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
24+
<div class="example-block">
25+
<p><strong>Input:</strong> <span class="example-io">nums = [1]</span></p>
26+
27+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
28+
29+
<p><strong>Explanation:</strong></p>
30+
31+
<p>There is only one element. So the answer is <code>true</code>.</p>
32+
</div>
33+
34+
<p><strong class="example">Example 2:</strong></p>
35+
36+
<div class="example-block">
37+
<p><strong>Input:</strong> <span class="example-io">nums = [2,1,4]</span></p>
38+
39+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
40+
41+
<p><strong>Explanation:</strong></p>
42+
43+
<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>
44+
</div>
45+
46+
<p><strong class="example">Example 3:</strong></p>
47+
48+
<div class="example-block">
49+
<p><strong>Input:</strong> <span class="example-io">nums = [4,3,1,6]</span></p>
50+
51+
<p><strong>Output:</strong> <span class="example-io">false</span></p>
52+
53+
<p><strong>Explanation:</strong></p>
54+
55+
<p><code>nums[1]</code> and <code>nums[2]</code> are both odd. So the answer is <code>false</code>.</p>
56+
</div>
57+
58+
<p>&nbsp;</p>
59+
<p><strong>Constraints:</strong></p>
60+
61+
<ul>
62+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
63+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
64+
</ul>
65+
66+
<!-- description:end -->
67+
68+
## Solutions
69+
70+
<!-- solution:start -->
71+
72+
### Solution 1
73+
74+
<!-- tabs:start -->
75+
76+
#### Python3
77+
78+
```python
79+
80+
```
81+
82+
#### Java
83+
84+
```java
85+
86+
```
87+
88+
#### C++
89+
90+
```cpp
91+
92+
```
93+
94+
#### Go
95+
96+
```go
97+
98+
```
99+
100+
<!-- tabs:end -->
101+
102+
<!-- solution:end -->
103+
104+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3152.Special%20Array%20II/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3152. 特殊数组 II](https://leetcode.cn/problems/special-array-ii)
10+
11+
[English Version](/solution/3100-3199/3152.Special%20Array%20II/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>如果数组的每一对相邻元素都是两个奇偶性不同的数字,则该数组被认为是一个 <strong>特殊数组</strong> 。</p>
18+
19+
<p>周洋哥有一个整数数组 <code>nums</code> 和一个二维整数矩阵 <code>queries</code>,对于 <code>queries[i] = [from<sub>i</sub>, to<sub>i</sub>]</code>,请你帮助周洋哥检查子数组 <code>nums[from<sub>i</sub>..to<sub>i</sub>]</code> 是不是一个 <strong>特殊数组 </strong>。</p>
20+
21+
<p>返回布尔数组 <code>answer</code>,如果 <code>nums[from<sub>i</sub>..to<sub>i</sub>]</code> 是特殊数组,则 <code>answer[i]</code> 为 <code>true</code> ,否则,<code>answer[i]</code> 为 <code>false</code> 。</p>
22+
23+
<p>&nbsp;</p>
24+
25+
<p><strong class="example">示例 1:</strong></p>
26+
27+
<div class="example-block">
28+
<p><strong>输入:</strong><span class="example-io">nums = [3,4,1,2,6], queries = [[0,4]]</span></p>
29+
30+
<p><strong>输出:</strong><span class="example-io">[false]</span></p>
31+
32+
<p><strong>解释:</strong></p>
33+
34+
<p>子数组是 <code>[3,4,1,2,6]</code>。2 和 6 都是偶数。</p>
35+
</div>
36+
37+
<p><strong class="example">示例 2:</strong></p>
38+
39+
<div class="example-block">
40+
<p><strong>输入:</strong><span class="example-io">nums = [4,3,1,6], queries = [[0,2],[2,3]]</span></p>
41+
42+
<p><strong>输出:</strong><span class="example-io">[false,true]</span></p>
43+
44+
<p><strong>解释:</strong></p>
45+
46+
<ol>
47+
<li>子数组是 <code>[4,3,1]</code>。3 和 1 都是奇数。因此这个查询的答案是 <code>false</code>。</li>
48+
<li>子数组是 <code>[1,6]</code>。只有一对:<code>(1,6)</code>,且包含了奇偶性不同的数字。因此这个查询的答案是 <code>true</code>。</li>
49+
</ol>
50+
</div>
51+
52+
<p>&nbsp;</p>
53+
54+
<p><strong>提示:</strong></p>
55+
56+
<ul>
57+
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
58+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
59+
<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
60+
<li><code>queries[i].length == 2</code></li>
61+
<li><code>0 &lt;= queries[i][0] &lt;= queries[i][1] &lt;= nums.length - 1</code></li>
62+
</ul>
63+
64+
<!-- description:end -->
65+
66+
## 解法
67+
68+
<!-- solution:start -->
69+
70+
### 方法一
71+
72+
<!-- tabs:start -->
73+
74+
#### Python3
75+
76+
```python
77+
78+
```
79+
80+
#### Java
81+
82+
```java
83+
84+
```
85+
86+
#### C++
87+
88+
```cpp
89+
90+
```
91+
92+
#### Go
93+
94+
```go
95+
96+
```
97+
98+
<!-- tabs:end -->
99+
100+
<!-- solution:end -->
101+
102+
<!-- problem:end -->

0 commit comments

Comments
 (0)