File tree 1 file changed +12
-11
lines changed
scripts/algorithms/D/Detect Capital
1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 7 ms (Top 10.31%) | Memory: 6 MB (Top 66.23%)
1
2
class Solution {
2
3
public:
3
4
bool detectCapitalUse (string word) {
4
5
int n = word.size ();
5
-
6
- // if the first letter of the string is lower-case
6
+
7
+ // if the first letter of the string is lower-case
7
8
if (islower (word[0 ])){
8
9
int c = 0 ;
9
10
for (int i=0 ; i<n; i++){
10
11
if (islower (word[i])){
11
12
c++;
12
13
}
13
14
}
14
-
15
- // total lower-case count must be equal to the size of the string
15
+
16
+ // total lower-case count must be equal to the size of the string
16
17
if (c == n){
17
18
return true ;
18
19
}
19
20
return false ;
20
21
}
21
-
22
- // if the first letter of the string is upper-case.
22
+
23
+ // if the first letter of the string is upper-case.
23
24
else {
24
25
int c = 0 ;
25
26
for (int i=0 ; i<n; i++){
26
27
if (isupper (word[i])){
27
28
c++;
28
29
}
29
30
}
30
-
31
- // count of total upper-case letters must be equal to 1 or to the size of the string.
31
+
32
+ // count of total upper-case letters must be equal to 1 or to the size of the string.
32
33
if (c == 1 or c == n){
33
34
return true ;
34
35
}
35
-
36
- // in all other cases, return false.
36
+
37
+ // in all other cases, return false.
37
38
return false ;
38
39
}
39
40
}
40
- };
41
+ };
You can’t perform that action at this time.
0 commit comments