-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path520.cpp
More file actions
25 lines (25 loc) · 767 Bytes
/
Copy path520.cpp
File metadata and controls
25 lines (25 loc) · 767 Bytes
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
class Solution {
public:
bool detectCapitalUse(string word) {
int n = word.size();
for (int i = 0; i < n; ++i) {
int j = i + 1;
while (j != n && word[j] != ' ')
++j;
if (j == i + 1) {
++i;
continue;
}
bool upper = false;
if (word[i] >= 'A' && word[i] <= 'Z' && word[i + 1] >= 'A' && word[i + 1] <= 'Z')
upper = true;
for (int k = i + 1; k < j; ++k) {
if (upper && word[k] >= 'a' && word[k] <= 'z')
return false;
if (!upper && word[k] >= 'A' && word[k] <= 'Z')
return false;
}
}
return true;
}
};