3227. Vowels Game in a String Medium
1/**
2 * [3227] Vowels Game in a String
3 *
4 * Alice and Bob are playing a game on a string.
5 * You are given a string s, Alice and Bob will take turns playing the following game where Alice starts first:
6 *
7 * On Alice's turn, she has to remove any non-empty <span data-keyword="substring">substring</span> from s that contains an odd number of vowels.
8 * On Bob's turn, he has to remove any non-empty <span data-keyword="substring">substring</span> from s that contains an even number of vowels.
9 *
10 * The first player who cannot make a move on their turn loses the game. We assume that both Alice and Bob play optimally.
11 * Return true if Alice wins the game, and false otherwise.
12 * The English vowels are: a, e, i, o, and u.
13 *
14 * <strong class="example">Example 1:
15 * <div class="example-block">
16 * Input: <span class="example-io">s = "leetcoder"</span>
17 * Output: <span class="example-io">true</span>
18 * Explanation:<br />
19 * Alice can win the game as follows:
20 *
21 * Alice plays first, she can delete the underlined substring in s = "<u>leetco</u>der" which contains 3 vowels. The resulting string is s = "der".
22 * Bob plays second, he can delete the underlined substring in s = "<u>d</u>er" which contains 0 vowels. The resulting string is s = "er".
23 * Alice plays third, she can delete the whole string s = "<u>er</u>" which contains 1 vowel.
24 * Bob plays fourth, since the string is empty, there is no valid play for Bob. So Alice wins the game.
25 * </div>
26 * <strong class="example">Example 2:
27 * <div class="example-block">
28 * Input: <span class="example-io">s = "bbcd"</span>
29 * Output: <span class="example-io">false</span>
30 * Explanation:<br />
31 * There is no valid play for Alice in her first turn, so Alice loses the game.
32 * </div>
33 *
34 * Constraints:
35 *
36 * 1 <= s.length <= 10^5
37 * s consists only of lowercase English letters.
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/vowels-game-in-a-string/
43// discuss: https://leetcode.com/problems/vowels-game-in-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn does_alice_win(s: String) -> bool {
49 false
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_3227() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.