2-liner C++

  • 0

    By definition, the capital usage is correct iff both conditions hold below:

    1. All letters in the word except first one must have same case.
    2. First letter must be upper case or last one must be lower case.
        bool detectCapitalUse(string w) {
          for (int i = 2; i < w.size(); ++i) if (isupper(w[1])-isupper(w[i])) return false;
          return isupper(w.front()) || islower(w.back());

Log in to reply

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