全部大写,比如 LEETCODE; 全部小写,比如 leetcode; 其它写法都是错的。 2.1 代码实现:暴力解法(切片 slicing) 所谓暴力解法,就是直接判断单词的大小写情况。 代码如下: ## 解法一:大小写判断 class Solution: def detectCapitalUse(self, word: str) -> bool: if word.isupper() or word.islower(): return...
Can you solve this real interview question? Detect Capital - 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,
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: True Example 2: In...
LeetCode: Detect Capital 这里利用'A'到'Z'都小于'a'到'z' 1publicclassSolution {2publicbooleandetectCapitalUse(String word) {3intnum = 0;4for(charc : word.toCharArray()) {5if('Z' - c >= 0) {6num++;7}8}9if(num == 0 || num == word.length())returntrue;10if(num == 1 &...
All letters in this word are not capitals, like "leetcode". Only the first letter in this word is capital, like "Google". Otherwise, we define that this word doesn't use capitals in a right way. Example 1: Input: "USA" Output: True Example 2: Input: "FlaG" Output: False检测...
520. Detect Capital # 题目 # 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
题目地址:https://leetcode.com/problems/detect-capital/description/ 题目大意:判断一个单词的大写字母是不是用法正确。 思路:很简单,先判断第一个字母,如果是大写字母,那么剩下的全得是大写字母或者小写字母,如果是小写字母,那么剩下的全都得是小写字母。注意:如果单词只有一个字母,直接返回True class Solution:...
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. ...
classSolution {public:booldetectCapitalUse(stringword) {intcnt = count_if(word.begin(), word.end(), [](charc){returnc <='Z';});returncnt ==0|| cnt == word.size() || (cnt ==1&& word[0] <='Z'); } }; 本文转自博客园Grandyang的博客,原文链接:[LeetCode] Detect Capital 检测...
LeetCode 520:Detect Capital(检测大写字母) Together for a Shared future 一起向未来 今天带来的题目是《520. 检测大写字母》。 题目描述 我们定义,在以下情况时,单词的大写用法是正确的: 全部字母都是大写,比如 "USA" 。 单词中所有字母都不是大写,比如 "leetcode" 。