forked from codedecks-in/LeetCode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect-capital-use.java
45 lines (36 loc) · 1.12 KB
/
detect-capital-use.java
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
45
class Solution {
public boolean detectCapitalUse(String word) {
int upperCaseCount = 0;
int lowerCaseCount = 0;
int wordLen = word.length();
int i = 0;
int firstCharFlag = 0;
for(i=0 ; i<wordLen; i++){
int ch = word.charAt(i);
if(ch >= 'a' && ch <= 'z'){
lowerCaseCount++;
}
else if(ch >= 'A' && ch <= 'Z'){
upperCaseCount++;
if(i == 0){
firstCharFlag++;
}
}
}
if(i == wordLen){
if(lowerCaseCount == wordLen){
return true;
}
else if(upperCaseCount == wordLen){
return true;
}
else if(firstCharFlag == 1 && upperCaseCount == 1 && lowerCaseCount == (wordLen-1)){
return true;
}
else{
return false;
}
}
return false;
}
}