Skip to content

Latest commit

 

History

History
75 lines (59 loc) · 1.77 KB

_3227. Vowels Game in a String.md

File metadata and controls

75 lines (59 loc) · 1.77 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Completed during Weekly Contest 407 (q2)

Back to top


First completed : July 21, 2024

Last updated : July 21, 2024


Related Topics : Math, String, Brainteaser, Game Theory

Acceptance Rate : 63.09 %


Notes

    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.

Solutions

Python

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)