Description
应该都能看懂吧……
Solution
一道简单的模拟题。
按照题意枚举字符串,判断元/辅音;判断合法即可。
也不知道今天的题为什么怎么淼
Code(C++、Python3)
C++
class Solution {
public:
bool isValid(string word) {
if (word.size() < 3) return false;
int e = 0, f = 0;
for (char c : word) {
if (isalpha(c)) {
c = tolower(c);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
e++;
} else {
f++;
}
} else if (!isdigit(c)){
return false;
}
}
return e && f;
}
};
Python3
class Solution:
def isValid(self, word: str) -> bool:
if len(word) < 3:
return False
e = f = False
for c in word:
if c.isalpha():
if (c.lower() in 'aeiou'):
e = True
else :
f = True
elif not c.isdigit():
return False
return e and f
欢迎大家关注LeetCode——C2h6oqwq。也恳求大家点赞收藏加关注~~~