3136: Valid-Word
Easy
table of contents
Basically, just iterate through the entire array and see if all the conditions have been satisfied.
code
class Solution {
public:
bool isValid(string word) {
if (word.size() < 3) {
return false;
}
bool hasVowel = false;
bool hasConsonant = false;
for (auto &c : word) {
if (isalpha(c)) {
= tolower(c);
c if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
= true;
hasVowel } else {
= true;
hasConsonant }
} else if (!isdigit(c)) {
return false;
}
}
return hasVowel && hasConsonant;
}
};