> For the complete documentation index, see [llms.txt](https://dfine.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dfine.gitbook.io/leetcode/520.detect_capital.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
