c++ solution


  • 0
    D
    class Solution {
    public:
        bool detectCapitalUse(string word) {
            if (word.size() <= 1)
                return true;
          
            int low2 = islower(word[1]);
            for (int i = word.size()-1; i > 1; --i) {
                if (islower(word[i]) ^ low2)
                    return false;
            }
            return low2 || (!islower(word[0]) && !low2);
        }
    };

Log in to reply
 

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