blob: 3fb2870311a65c8fe3b9b4d7ff714fad0e8a8e02 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#!/usr/bin/env python
class Solution:
def halvesAreAlike(self, s: str) -> bool:
vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
length = len(s) // 2
first = 0
second = 0
for i in range(0, length):
if s[i] in vowels:
first += 1
if s[length + i] in vowels:
second += 1
if first == second:
return True
return False
def main():
solution = Solution()
print(solution.halvesAreAlike("book"))
print(solution.halvesAreAlike("textbook"))
print(solution.halvesAreAlike("AbCdEfGh"))
if __name__ == "__main__":
main()
|