标签:tle als follow div href back problems bool let
leetcode-520-Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.
We define the usage of capitals in a word to be right when one of the following cases holds:
Example 1:
Input: "USA" Output: True
Example 2:
Input: "FlaG" Output: False
Note: The input will be a non-empty word consisting of uppercase and lowercase latin letters.
使用模拟法,模拟通过,easy 题目
class Solution {
public:
bool detectCapitalUse(string word) {
int j, i = 0, len = word.size();
while(i < len){
if(word[i] >= ‘A‘ && word[i] <= ‘Z‘){
if(i > 0 && word[i-1] !=‘ ‘){
return false;
}
j = i+1;
while(j < len && word[j]>=‘A‘ && word[j]<=‘Z‘){
j++;
}
if(j < len && j>(i+1) && word[j] != ‘ ‘){
return false;
}
i = j;
}else{
i++;
}
}
return true;
}
};
标签:tle als follow div href back problems bool let
原文地址:http://www.cnblogs.com/zhang-yd/p/6415827.html