判断一个字符串前一半和后一半是否含有相同数量的元音字母,水题
1 #1704
2 #Runtime: 60 ms
3 #Memory Usage: 13.6 MB
4
5 class Solution(object):
6 def halvesAreAlike(self, s):
7 """
8 :type s: str
9 :rtype: bool
10 """
11 n1, n2 = 0, 0
12 vowel = ('A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u')
13 for i in range(0, len(s) / 2):
14 if s[i] in vowel:
15 n1 += 1
16 if s[i + len(s) / 2] in vowel:
17 n2 += 1
18 return n1 == n2