8000 feat: solved 3151. Special Array I · realtemirov/leetcode@851d007 · GitHub
[go: up one dir, main page]

Skip to content

Commit 851d007

Browse files
committed
feat: solved 3151. Special Array I
1 parent fffc374 commit 851d007

File tree

6 files changed

+75
-2
lines changed

6 files changed

+75
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 3151. Special Array I
2+
3+
🟩 Easy
4+
5+
## Solution
6+
7+
My Solution
8+
9+
```go
10+
func isArraySpecial(nums []int) bool {
11+
for i:=1; i<len(nums); i++ {
12+
if nums[i-1] % 2 == nums[i] % 2 {
13+
return false
14+
}
15+
}
16+
return true
17+
}
18+
```
19+
20+
![result](3151.png)
21+
22+
Leetcode: [link](https://leetcode.com/problems/special-array-i/)

Problems/3151/3151.png

31 KB
Loading

Problems/3151/solution.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package problem3151
2+
3+
func IsArraySpecial(nums []int) bool {
4+
for i := 1; i < len(nums); i++ {
5+
if nums[i-1]%2 == nums[i]%2 {
6+
return false
7+
}
8+
}
9+
return true
10+
}

Problems/3151/solution_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package problem3151_test
2+
3+
import (
4+
"testing"
5+
6+
problem3151 "github.com/realtemirov/leetcode/Problems/3151"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestSolution(t *testing.T) {
11+
testCases := []struct {
12+
name string
13+
cases []int
14+
expected bool
15+
}{
16+
{
17+
name: "Test 1",
18+
cases: []int{1},
19+
expected: true,
20+
},
21+
{
22+
name: "Test 2",
23+
cases: []int{2, 1, 4},
24+
expected: true,
25+
},
26+
{
27+
name: "Test 3",
28+
cases: []int{4, 3, 1, 6},
29+
expected: false,
30+
},
31+
}
32+
33+
for _, tc := range testCases {
34+
t.Run(tc.name, func(t *testing.T) {
35+
result := problem3151.IsArraySpecial(tc.cases)
36+
require.Equal(t, tc.expected, result, "expected: %v, result: %v", tc.expected, result)
37+
})
38+
}
39+
}

Problems/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Problems
22

3-
> **Total:** `92` \
4-
> **Easy:** `66` \
3+
> **Total:** `93` \
4+
> **Easy:** `67` \
55
> **Medium:** `26` \
66
> **Hard:** `0`
77
@@ -96,4 +96,5 @@
9696
* 🟧 Medium - [2559. Count Vowel Strings in Ranges](<./2559/2559. Count Vowel Strings in Ranges.md>)
9797
* 🟧 Medium - [2657. Find the Prefix Common Array of Two Arrays](<./2657/2657. Find the Prefix Common Array of Two Arrays.md>)
9898
* 🟩 Easy - [3042. Count Prefix and Suffix Pairs I](<./3042/3042. Count Prefix and Suffix Pairs I.md>)
99+
* 🟩 Easy - [3151. Special Array I](<./3151/3151. Special Array I.md>)
99100
* 🟧 Medium - [3223. Minimum Length of String After Operations](<./3223/3223. Minimum Length of String After Operations.md>)

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
* [2559. Count Vowel Strings in Ranges](<./Problems/2559/2559. Count Vowel Strings in Ranges.md>)
152152
* [2657. Find the Prefix Common Array of Two Arrays](<./Problems/2657/2657. Find the Prefix Common Array of Two Arrays.md>)
153153
* [3042. Count Prefix and Suffix Pairs I](<./Problems/3042/3042. Count Prefix and Suffix Pairs I.md>)
154+
* [3151. Special Array I](<./Problems/3151/3151. Special Array I.md>)
154155
* [3223. Minimum Length of String After Operations](<./Problems/3223/3223. Minimum Length of String After Operations.md>)
155156
<!--
156157

0 commit comments

Comments
 (0)
0