Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add solution and test-cases for problem 3227 #1163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
44 changes: 31 additions & 13 deletions leetcode/3201-3300/3227.Vowels-Game-in-a-String/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
# [3227.Vowels Game in a String][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

Alice and Bob are playing a game on a string.

You are given a string `s`, Alice and Bob will take turns playing the following game where Alice starts **first**:

- On Alice's turn, she has to remove any **non-empty** substring from `s` that contains an **odd** number of vowels.
- On Bob's turn, he has to remove any **non-empty** substring from `s` that contains an **even** number of vowels.

The first player who cannot make a move on their turn loses the game. We assume that both Alice and Bob play **optimally**.

Return `true` if Alice wins the game, and `false` otherwise.

The English vowels are: `a`, `e`, `i`, `o`, and `u`.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
```
Input: s = "leetcoder"

Output: true

Explanation:
Alice can win the game as follows:

## 题意
> ...
Alice plays first, she can delete the underlined substring in s = "leetcoder" which contains 3 vowels. The resulting string is s = "der".
Bob plays second, he can delete the underlined substring in s = "der" which contains 0 vowels. The resulting string is s = "er".
Alice plays third, she can delete the whole string s = "er" which contains 1 vowel.
Bob plays fourth, since the string is empty, there is no valid play for Bob. So Alice wins the game.
```

## 题解
**Example 2:**

### 思路1
> ...
Vowels Game in a String
```go
```
Input: s = "bbcd"

Output: false

Explanation:
There is no valid play for Alice in her first turn, so Alice loses the game.
```

## 结语

Expand Down
9 changes: 7 additions & 2 deletions leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(s string) bool {
for _, e := range s {
if e == 'a' || e == 'e' || e == 'i' || e == 'o' || e == 'u' {
return true
}
}
return false
}
11 changes: 5 additions & 6 deletions leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
inputs string
expect bool
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", "leetcode", true},
{"TestCase2", "bbcd", false},
}

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

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

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