Leetcode 520. Detect Capital

Source: Internet
Author: User

Given A word, you need to judge whether the usage of capitals in it are right or not.

We define the usage of capitals in a word to being right when one of the following cases holds:

    1. All letters in this word is capitals, like "USA".
    2. All letters in this word is not capitals, like "Leetcode".
    3. Only the first letter of this word was capital if it had more than one letter, like "Google".

Otherwise, we define that this word doesn ' t use capitals in a right-to-do.

Example 1:

Input: "USA" output:true

Example 2:

Input: "FlaG" Output:false

Note:the input is a non-empty word consisting of uppercase and lowercase Latin letters.

This problem stunned me, I thought is must be equal to the USA or leetcode just let, and then the rest of the word is the first letter capitalization, the results are not submitted wrong, then really do not want to search someone else's answer, the result, found that I understand the wrong = =,,

var function (word) {    return /^ ([a-z]+|[ a-z]+| [A-z] [a-z]+) $/. Test (Word);      };

The regular expression is done!

Leetcode 520. Detect Capital

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.