70. Detect Capital(쉬움)
07 Sep 2020 | Daily Algorithms
class Solution {
public:
bool detectCapitalUse(string word) {
int n = word.size();
if(n==1)
return true;
int cap = 0;
for(auto c : word)
{
if(c<97) // if c is less than 'a' means Capital, cap++
cap++;
}
if(cap == 1)
return word[0]<97; // check if the first character is captial;
else
return cap == 0 || cap == n; // All capital or all lowercase
}
};
class Solution {
public:
bool detectCapitalUse(string word) {
int n = word.size();
if(n==1)
return true;
int cap = 0;
for(auto c : word)
{
if(c<97) // if c is less than 'a' means Capital, cap++
cap++;
}
if(cap == 1)
return word[0]<97; // check if the first character is captial;
else
return cap == 0 || cap == n; // All capital or all lowercase
}
};
Comments