-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path520_Detect_Capital.cpp
41 lines (39 loc) · 1.08 KB
/
520_Detect_Capital.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Solution {
public:
bool isCapital(char c){
if(c<='Z' && c>='A')
return true;
return false;
}
bool detectCapitalUse(string word) {
if(word.size()==1)
return true;
if(word.size()==2){
if(isCapital(word[1] && !isCapital(word[0])))
return false;
else if(!isCapital(word[0]) && isCapital(word[1]))
return false;
else
return true;
}
if(isCapital(word[0]) && isCapital(word[1])){
for (int i=2;i<word.size();i++){
if(!isCapital(word[i]))
return false;
}
}
if(isCapital(word[0]) && !isCapital(word[1])){
for(int i=2;i<word.size();i++){
if(isCapital(word[i]))
return false;
}
}
if(!isCapital(word[0])){
for(int i=1;i<word.size();i++){
if(isCapital(word[i]))
return false;
}
}
return true;
}
};