Skip to content

Commit efc7c54

Browse files
committed
Add solution and test-cases for problem 3227
1 parent f0a9eb1 commit efc7c54

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

leetcode/3201-3300/3227.Vowels-Game-in-a-String/README.md

+31-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
# [3227.Vowels Game in a String][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
74

5+
Alice and Bob are playing a game on a string.
6+
7+
You are given a string `s`, Alice and Bob will take turns playing the following game where Alice starts **first**:
8+
9+
- On Alice's turn, she has to remove any **non-empty** substring from `s` that contains an **odd** number of vowels.
10+
- On Bob's turn, he has to remove any **non-empty** substring from `s` that contains an **even** number of vowels.
11+
12+
The first player who cannot make a move on their turn loses the game. We assume that both Alice and Bob play **optimally**.
13+
14+
Return `true` if Alice wins the game, and `false` otherwise.
15+
16+
The English vowels are: `a`, `e`, `i`, `o`, and `u`.
17+
818
**Example 1:**
919

1020
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
13-
```
21+
Input: s = "leetcoder"
22+
23+
Output: true
24+
25+
Explanation:
26+
Alice can win the game as follows:
1427
15-
## 题意
16-
> ...
28+
Alice plays first, she can delete the underlined substring in s = "leetcoder" which contains 3 vowels. The resulting string is s = "der".
29+
Bob plays second, he can delete the underlined substring in s = "der" which contains 0 vowels. The resulting string is s = "er".
30+
Alice plays third, she can delete the whole string s = "er" which contains 1 vowel.
31+
Bob plays fourth, since the string is empty, there is no valid play for Bob. So Alice wins the game.
32+
```
1733

18-
## 题解
34+
**Example 2:**
1935

20-
### 思路1
21-
> ...
22-
Vowels Game in a String
23-
```go
2436
```
37+
Input: s = "bbcd"
38+
39+
Output: false
2540
41+
Explanation:
42+
There is no valid play for Alice in her first turn, so Alice loses the game.
43+
```
2644

2745
## 结语
2846

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(s string) bool {
4+
cnt := 0
5+
for _, e := range s {
6+
if e == 'a' || e == 'e' || e == 'i' || e == 'o' || e == 'u' {
7+
cnt++
8+
}
9+
}
10+
return cnt != 0
511
}

leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
13+
inputs string
1414
expect bool
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", "leetcode", true},
17+
{"TestCase2", "bbcd", false},
1918
}
2019

2120
// 开始测试
@@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
3029
}
3130
}
3231

33-
// 压力测试
32+
// 压力测试
3433
func BenchmarkSolution(b *testing.B) {
3534
}
3635

37-
// 使用案列
36+
// 使用案列
3837
func ExampleSolution() {
3938
}

0 commit comments

Comments
 (0)