Skip to content

Commit 0424b7a

Browse files
authored
Create 520.cpp
1 parent f412550 commit 0424b7a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

leetcode/cpp/string/520.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
class Solution {
2+
public:
3+
bool detectCapitalUse(string word) {
4+
bool upper=true,lower=true;
5+
if(word[0]-'A'>=0&&word[0]-'A'<26)
6+
{
7+
for(int i=1;i<word.size();i++)
8+
{
9+
if(word[i]-'a'>=0&&word[i]-'a'<26)
10+
{
11+
continue;
12+
}
13+
else{
14+
lower=false;
15+
break;
16+
}
17+
}
18+
for(int i=1;i<word.size();i++)
19+
{
20+
if(word[i]-'A'>=0&&word[i]-'A'<26)
21+
{
22+
continue;
23+
}
24+
else{
25+
upper=false;
26+
break;
27+
}
28+
}
29+
}
30+
else{
31+
upper=false;
32+
for(int i=1;i<word.size();i++)
33+
{
34+
if(word[i]-'a'>=0&&word[i]-'a'<26)
35+
{
36+
continue;
37+
}
38+
else{
39+
lower=false;
40+
break;
41+
}
42+
}
43+
}
44+
bool ans=upper|lower;
45+
return ans;
46+
}
47+
};

0 commit comments

Comments
 (0)