Detect Capital LeetCode solution in C++
1class Solution {2public:3bool detectCapitalUse(string word) {4int n = word.size();56// if the first letter of the string is lower-case7if (islower(word[0])) {8int c = 0;9for (int i = 0; i < n; i++) {10if (islower(word[i])) {11c++;12}13}1415// total lower-case count must be equal to the size of the string16if (c == n) {17return true;18}19return false;20}2122// if the first letter of the string is upper-case.23else {24int c = 0;25for (int i = 0; i < n; i++) {26if (isupper(word[i])) {27c++;28}29}3031// count of total upper-case letters must be equal to 1 or to the size of32// the string.33if (c == 1 or c == n) {34return true;35}3637// in all other cases, return false.38return false;39}40}41};