# 520.Detect Capital

**520.Detect Capital**

难度:Easy

> 给定一个单词，你需要判断单词的大写使用是否正确。

我们定义，在以下情况时，单词的大写用法是正确的：

全部字母都是大写，比如"USA"。 单词中所有字母都不是大写，比如"leetcode"。 如果单词不只含有一个字母，只有首字母大写， 比如 "Google"。 否则，我们定义这个单词没有正确使用大写字母。

示例 1:

```
输入: "USA"
输出: True
示例 2:

输入: "FlaG"
输出: False
```

注意: 输入是由大写和小写拉丁字母组成的非空单词。

简单题，直接条件判断：

```
class Solution {
public:
    bool detectCapitalUse(string word) {
        if(word[0]>='A' && word[0] <='Z')
        {
            if(word.size()<=2) return true;
            if(word[1]>='A' && word[1]<='Z') 
            {
                for(int i=2;i<word.size();i++)
                    if(word[i]>='a' && word[i]<='z') return false;
            }
            else
            {
                for(int i=2;i<word.size();i++)
                    if(word[i]>='A' && word[i]<='Z') return false;
            }
        }
        else
            for(auto c: word)
                if(c>='A' && c<='Z') return false;
        return true;
    }
};
```

> 执行用时 : 8 ms, 在Detect Capital的C++提交中击败了93.06% 的用户\
> 内存消耗 : 8.1 MB, 在Detect Capital的C++提交中击败了91.24% 的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/520.detect_capital.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
