aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-09-11 21:00:21 -0600
committerJack Sangdahl <[email protected]>2025-09-11 21:00:21 -0600
commita6c1d15471d1a7f32d43b9c03891fb52698de61f (patch)
treec502418596d3853620317ebb08043ac50366d4e5
parent144aefa71917d45782ac4673a934b3b4e7523413 (diff)
downloadleetcode-a6c1d15471d1a7f32d43b9c03891fb52698de61f.tar.gz
leetcode-a6c1d15471d1a7f32d43b9c03891fb52698de61f.zip
3227. vowels game in a string
-rw-r--r--vowels_game_string.c28
-rw-r--r--vowels_game_string.py29
2 files changed, 57 insertions, 0 deletions
diff --git a/vowels_game_string.c b/vowels_game_string.c
new file mode 100644
index 0000000..3f658c2
--- /dev/null
+++ b/vowels_game_string.c
@@ -0,0 +1,28 @@
+// 3227. Vowels Game in a String
+#include "leetcode.h"
+
+/*
+ * 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 bob and alice play optimally. return true if alice wins, and false
+ * otherwise.
+ */
+
+bool doesAliceWin(char *s) {
+ for (; *s; ++s) {
+ char curr = *s;
+ if (curr == 'a' || curr == 'e' || curr == 'i' || curr == 'o' || curr == 'u')
+ return true;
+ }
+ return false;
+}
+
+int main() {
+ char *s1 = "leetcoder", *s2 = "bbcd";
+ printf("%d\n", doesAliceWin(s1)); // expect: 1
+ printf("%d\n", doesAliceWin(s2)); // expect: 0
+}
diff --git a/vowels_game_string.py b/vowels_game_string.py
new file mode 100644
index 0000000..d56d53a
--- /dev/null
+++ b/vowels_game_string.py
@@ -0,0 +1,29 @@
+# 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 bob and alice play optimally. return true if alice wins, and false
+"""
+
+
+class Solution(object):
+ def doesAliceWin(self, s):
+ """
+ :type s: str
+ :rtype: bool
+ """
+ for i in s:
+ if i in "aeiou":
+ return True
+ return False
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.doesAliceWin(s="leetcoder"))
+ print(obj.doesAliceWin(s="bbcd"))