blob: 27aa46b23b49a0bd8dc7ef52a81852475b8ff6aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include "leetcode.h"
class Solution {
public:
bool detectCapitalUse(string word) {
bool firstCaps = isupper(word[0]), allCaps = true, allLower = true;
for (int i = 1; i < word.size(); i++) {
if (isupper(word[i]))
allLower = false;
else
allCaps = false;
}
return (firstCaps && allCaps) || allLower;
}
};
int main() {
Solution obj;
testBool(obj.detectCapitalUse("USA")); // true
testBool(obj.detectCapitalUse("FlaG")); // false
}
|