diff --git a/leetcode/3201-3300/3227.Vowels-Game-in-a-String/README.md b/leetcode/3201-3300/3227.Vowels-Game-in-a-String/README.md index 0e1001c83..9cba51376 100755 --- a/leetcode/3201-3300/3227.Vowels-Game-in-a-String/README.md +++ b/leetcode/3201-3300/3227.Vowels-Game-in-a-String/README.md @@ -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. +``` ## 结语 diff --git a/leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution.go b/leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution.go index d115ccf5e..c140ecfb5 100644 --- a/leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution.go +++ b/leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution.go @@ -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 } diff --git a/leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution_test.go b/leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution_test.go index 14ff50eb4..ab49d64b8 100644 --- a/leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution_test.go +++ b/leetcode/3201-3300/3227.Vowels-Game-in-a-String/Solution_test.go @@ -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}, } // 开始测试 @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) { } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }