111.有效单词
class Solution {
public boolean isValid(String word) {
if(word.length()<3){
return false;
}
int countV=0,countC=0;//分别统计原音和辅音
for(int i=0;i<word.length();i++){
if(Character.isLetterOrDigit(word.charAt(i))){
if(word.charAt(i)=='a'||word.charAt(i)=='e'||word.charAt(i)=='i'||word.charAt(i)=='o'||word.charAt(i)=='u'||word.charAt(i)=='A'||word.charAt(i)=='E'||word.charAt(i)=='I'||word.charAt(i)=='O'||word.charAt(i)=='U'){
countC++;
}
else if(Character.isLetter(word.charAt(i))){
countV++;
}
}
else{
return false;
}
}
return countC>0&&countV>0;
}
}
class Solution(object):
def isValid(self, word):
if len(word)<3:
return False
countV,countC=0,0;#分别统计原音和辅音
for i in range(len(word)):
if word[i].isdigit() or word[i].isalpha():
if word[i]=="a" or word[i]=="e" or word[i]=="i" or word[i]=='o' or word[i]=='u' or word[i]=='A' or word[i]=='E' or word[i]=='I' or word[i]=='O' or word[i]=='U':
countC+=1
elif word[i].isalpha():
countV+=1
else:
return False
return countC>0 and countV>0
原文地址:https://blog.csdn.net/Runner__Binger/article/details/144066298
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!