Given a Word, you need to judge whether the usage of capitals in it is right or not.
We define the usage of capitals in a word to be right when one of the following cases holds:
All letters in this word are capitals, like “USA”. All letters in this word are not capitals, like “leetcode”. Only the first letter in this word is capital if it has more than one letter, like “Google”.Otherwise, we define that this word doesn’t use capitals in a right way.
Example 1:Input: "USA"Output: TrueExample 2:Input: "FlaG"Output: FalseNote: The input will be a non-empty word consisting of uppercase and lowercase latin letters.
class Solution {public: bool detectCapitalUse(string word) { }};檢測資本 給定一個詞,你需要判斷它中的資本的使用是否正確。
當以下情況之一存在時,我們將單詞中資本的使用定義為正確:
這個單詞中的所有字母都是大寫,如“USA”。 這個單詞中的所有字母都不是大寫,例如“leetcode”。 只有此字中的第一個字母是大寫,如果它有多個字母,如“Google”。 否則,我們定義這個詞不以正確的方式使用大寫。注意:輸入將是由大寫和小寫拉丁字母組成的非空字。
這就是一個要求不斷實現幾個要實現的條件的題,重點是要如何去設置條件。
遇到多條件的,我的通常做法是:先把條件列下來,然后看哪些條件可以歸類,成為同一組,或者說用一個表達式表示多個條件,這樣就可以達到間接的目的。
都是大寫都是小寫如果有多個字母,頭字母大寫合并: 首先判斷是不是一個字母,則不論大小寫都符合, 。。。。。
新聞熱點
疑難解答
圖片精選