-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectCapitalUse-LCQ.cpp
More file actions
44 lines (34 loc) · 1.01 KB
/
DetectCapitalUse-LCQ.cpp
File metadata and controls
44 lines (34 loc) · 1.01 KB
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
42
43
44
/*
Detect Capital
We define the usage of capitals in a word to be right when one of the following cases holds:
All letters in this word are capitals, like "USA".
All letters in this word are not capitals, like "leetcode".
Only the first letter in this word is capital, like "Google".
Given a string word, return true if the usage of capitals in it is right.
Example 1:
Input: word = "USA"
Output: true
Example 2:
Input: word = "FlaG"
Output: false
Constraints:
1 <= word.length <= 100
word consists of lowercase and uppercase English letters.
*/
class Solution {
public:
bool detectCapitalUse(string word) {
int countUpp=0,countLow=0;
for(int i=0;i<word.size();i++){
if(word[i]>='A' && word[i]<='Z')
countUpp++;
else
countLow++;
}
if(countUpp==1 && (word[0]>='A' && word[0]<='Z'))
return true;
if(countUpp==word.size() || countLow==word.size())
return true;
return false;
}
};