520. Detecting Uppercase letters

Source: Internet
Author: User

Given a word, you need to determine whether the capitalization of the word is used correctly.

We define that the capitalization usage of a word is correct in the following cases:

1. All letters are capitalized, such as "USA".

2. All letters in the word are not uppercase, such as "Leetcode".

3. If the word contains more than one letter, only the first letter is capitalized, such as "Google".

Otherwise, we define that the word does not use uppercase letters correctly.

Example 1:

Input: "USA"
Output: True
Example 2:

Input: "FlaG"
Output: False
Note: The input is a non-empty word made up of uppercase and lowercase Latin letters.

1varUpper =' ABCDEFGHIJKLMNOPQRSTUVWXYZ ';
2varDetectcapitaluse = function (word){
3varj =0
4 for(varI=0; i<word.length; i++) {
5if(Upper.includes (Word[i)) J + +
6}
7
8if(J===word.length | | j===0)returntrue
9if(j===1&& Upper.includes (word[0]))returntrue
Tenreturn false
One}

520. Detecting Uppercase letters

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.