File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public boolean detectCapitalUse (String word ) {
3+
4+ int upperCaseCount = 0 ;
5+ int lowerCaseCount = 0 ;
6+
7+ int wordLen = word .length ();
8+
9+ int i = 0 ;
10+ int firstCharFlag = 0 ;
11+
12+ for (i =0 ; i <wordLen ; i ++){
13+ int ch = word .charAt (i );
14+
15+ if (ch >= 'a' && ch <= 'z' ){
16+ lowerCaseCount ++;
17+ }
18+ else if (ch >= 'A' && ch <= 'Z' ){
19+ upperCaseCount ++;
20+
21+ if (i == 0 ){
22+ firstCharFlag ++;
23+ }
24+ }
25+ }
26+
27+
28+ if (i == wordLen ){
29+ if (lowerCaseCount == wordLen ){
30+ return true ;
31+ }
32+ else if (upperCaseCount == wordLen ){
33+ return true ;
34+ }
35+ else if (firstCharFlag == 1 && upperCaseCount == 1 && lowerCaseCount == (wordLen -1 )){
36+ return true ;
37+ }
38+ else {
39+ return false ;
40+ }
41+ }
42+
43+ return false ;
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments