Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions leetcode/3101-3200/3151.Special-Array-I/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
# [3151.Special Array I][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
## Description
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: a = "11", b = "1"
Output: "100"
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:**

### 思路1
> ...
Special Array I
```go
```
Input: nums = [4,3,1,6]
Output: false
Explanation:
nums[1] and nums[2] are both odd. So the answer is false.
```

## 结语

Expand Down
12 changes: 10 additions & 2 deletions leetcode/3101-3200/3151.Special-Array-I/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(nums []int) bool {
if len(nums) == 1 {
return true
}
for i := 0; i < len(nums)-1; i++ {
if nums[i]&1 == nums[i+1]&1 {
return false
}
}
return true
}
12 changes: 6 additions & 6 deletions leetcode/3101-3200/3151.Special-Array-I/Solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
inputs []int
expect bool
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", []int{1}, true},
{"TestCase2", []int{2, 1, 4}, true},
{"TestCase3", []int{4, 3, 1, 6}, false},
}

// 开始测试
Expand All @@ -30,10 +30,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading