C++ solution(easy to understand)


  • 0
    T
    class Solution {
    public:
        bool detectCapitalUse(string word) {
            int numOfUpper = 0;
            for(int i=0; i<word.size(); i++){
                if(word[i] >= 'A' && word[i] <= 'Z'){
                    numOfUpper++;
                }
            }
            return (numOfUpper == word.size() || numOfUpper == 0 || (numOfUpper == 1 && word[0] >= 'A' && word[0] <= 'Z') );
        }
    };
    

Log in to reply
 

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