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