[C++] Make use of standard library.


  • 0
    Y

    Though it's neither shortest nor fastest, it still worth to have a look of the standard library.

    bool detectCapitalUse(string word) {
            
        auto upper = [](const char &c){ return isupper(c); };
        auto lower = [](const char &c){ return islower(c); };
        
        if (islower(word[0])) return all_of(word.begin(), word.end(), lower);
        return all_of(word.begin() + 1, word.end(), upper) || all_of(word.begin() + 1, word.end(), lower);
    }
    

    Functions about predicates include all_of, none_of, any_of, find_if, etc.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.