3227. Vowels Game in a String
All prompts are owned by LeetCode. To view the prompt, click the title link above.
Completed during Weekly Contest 407 (q2)
First completed : July 21, 2024
Last updated : July 21, 2024
Related Topics : Math, String, Brainteaser, Game Theory
Acceptance Rate : 63.09 %
Greedy? leetcoder --> l ee tc o d e r --> ee, o, e aabbbb alice: a remaining: abbbb bob: cannot Idea If len(vowels) > 0 Alice takes all but one If len(vowels) == odd : Alice takes all
In version 2, which I did after the contest, I realized that I could simplify the process by just searching for the first match. This gets rid of the redundancy of continuously searching after one case has been found since Alice is guarenteed to win if there's at least one single vowel.
class Solution:
def doesAliceWin(self, s: str) -> bool:
return re.search('[aeiou]{1}', s)
class Solution:
def doesAliceWin(self, s: str) -> bool:
vowels = re.findall('[aeiou]{1}', s)
return (len(vowels) > 0)