problem
题意:
题目中给出的三种情况,分别是全是大写、全是小写、首字母大写,这三种情况返回True;否则返回False;
solution:
class Solution { public: bool detectCapitalUse(string word) { bool flag = false; int cnt = 0; for(int i=0; i<word.size(); i++) { char ch = word[i]; if(ch>=‘A‘&&ch<=‘Z‘) cnt++; } if(cnt==word.size() || (cnt==1&& word[0]>=‘A‘&&word[0]<=‘Z‘) || cnt==0) //err { flag = true; } return flag; } };
参考
1. Leetcode_520. Detect Capital;
完