Skip to content

Commit cd99329

Browse files
committed
Time: 0 ms (100.00%), Space: 6.1 MB (70.23%) - LeetHub
1 parent 1faa2c0 commit cd99329

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
public:
3+
bool detectCapitalUse(string word) {
4+
5+
vector<string> ans;
6+
7+
stringstream ss(word);
8+
string ok;
9+
10+
while(ss >> ok)
11+
ans.push_back(ok);
12+
13+
for(auto itr : ans)
14+
{
15+
int caps = 0, small = 0, firstCaps = 0;
16+
17+
if(itr[0] >= 'A' and itr[0] <= 'Z')
18+
firstCaps = 1;
19+
for(auto x : itr)
20+
{
21+
if(x >= 'a' and x <= 'z')
22+
++small;
23+
else
24+
++caps;
25+
}
26+
if(small == itr.size() or caps == itr.size() or (firstCaps == 1 and small == itr.size()-1))
27+
{
28+
29+
}
30+
else
31+
return false;
32+
}
33+
return true;
34+
}
35+
};

0 commit comments

Comments
 (0)