We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ffbf90b commit d135248Copy full SHA for d135248
3775-reverse-words-with-same-vowel-count/3775-reverse-words-with-same-vowel-count.py
@@ -0,0 +1,20 @@
1
+# time complexity: O(n)
2
+# space complexity: O(n)
3
+class Solution:
4
+ def reverseWords(self, s: str) -> str:
5
+ vowels = set("aeiou")
6
+ words = s.split()
7
+ targetCount = sum(1 for c in words[0] if c in vowels)
8
+ for i in range(1, len(words)):
9
+ vowelCount = sum(1 for c in words[i] if c in vowels)
10
+ if vowelCount == targetCount:
11
+ words[i] = words[i][::-1]
12
+ return " ".join(words)
13
+
14
15
+s = "cat and mice"
16
+print(Solution().reverseWords(s))
17
+s = "book is nice"
18
19
+s = "banana healthy"
20
0 commit comments