[LeetCode] Vowels Game in a String

3227. Vowels Game in a String

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.

1
2
3
4
5
6
7
8
9
10
class Solution {
public:
bool doesAliceWin(string s) {
unordered_set<char> v{'a','e','i','o','u'};
for(auto& ch : s) {
if(v.count(ch)) return true;
}
return false;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2024/07/21/PS/LeetCode/vowels-game-in-a-string/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.