Leetcode学习(18)—— Detect Capital
来源:互联网 发布:网络推广工作安排 编辑:程序博客网 时间:2024/06/10 23:57
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.
一句话,你需要判断大写字母的使用是否正确。
当以下情况之一成立时,我们将一个单词中的大写字母的使用定义为正确:
这个词中的所有字母都是大写字母,如“美国”。
这个词中的所有字母都不是大写字母,例如“leetcode”。
只有这个词中的第一个字母是大写字母,如果它有多个字母,如“Google”。
否则,我们定义这个词不以正确的方式使用大写字母。
Example 1:Input: "USA"Output: TrueExample 2:Input: "FlaG"Output: False
Note: The input will be a non-empty word consisting of uppercase and lowercase latin letters.
import reclass Solution(object): def detectCapitalUse(self, word): pattern = re.compile(r'[A-Z]{1}') return_list = pattern.findall(word) # print(return_list) if len(return_list) == len(word): return True elif len(return_list) == 1 and return_list[0] == word[0]: return True elif len(return_list) == 0: return True else: return False
- Leetcode学习(18)—— Detect Capital
- LeetCode——520. Detect Capital
- LeetCode520—Detect Capital
- LeetCode 520. Detect Capital (字符串)
- LeetCode 520:Detect Capital (c++)
- leetcode 520. Detect Capital(C语言)
- 【Leetcode】520. Detect Capital
- LeetCode 520. Detect Capital
- leetcode-520-Detect Capital
- LeetCode 520. Detect Capital
- LeetCode:Detect Capital
- LeetCode-520. Detect Capital
- Leetcode #520 Detect Capital
- leetcode 520. Detect Capital
- leetcode 520. Detect Capital
- [leetcode] 520. Detect Capital
- [LeetCode]520 Detect Capital
- [LeetCode]520. Detect Capital
- 简述java语言特点
- 关于网站的一些小知识
- c++语言统计数字个数
- 一天搞定CSS:盒模型content、padding、border、margin--06
- swift oc混编 打包framwork
- Leetcode学习(18)—— Detect Capital
- C4.5决策树算法(Python实现)
- 多线程
- JavaScript语言基础---(十二)dom模型
- java类设计的基本原则
- Oracle11gR2 RAC for Windows安装下篇:Database 安装 简要步骤
- 设计模式->结构型模式->外观模式(门面模式)
- linux下unlink的使用
- Linux Namespace