Simple C++ code


  • 0
    S

    class Solution {
    public:
    bool detectCapitalUse(string word) {
    int length = word.size();
    if (length == 0) return false;
    if (length == 1) return true;
    if (islower(word[0])) {
    for (int i = 1; i < length; i++)
    if (isupper(word[i]))
    return false;
    return true;
    }
    else if (isupper(word[1])){
    for (int i = 2; i < length; i++)
    if (islower(word[i]))
    return false;
    return true;
    }
    else {
    for (int i = 2; i < length; i++)
    if (isupper(word[i]))
    return false;
    return true;
    }
    }
    };


Log in to reply
 

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