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)) {
                c = tolower(c);
                if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
                    hasVowel = true;
                } else {
                    hasConsonant = true;
                }
            } else if (!isdigit(c)) {
                return false;
            }
        }

        return hasVowel && hasConsonant;
    }
};

complexity

time taken