[LeetCode&Python] Problem 520. Detect Capital
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: True
Example 2:
Input: "FlaG"
Output: False
Note: The input will be a non-empty word consisting of uppercase and lowercase latin letters.
class Solution(object):
def detectCapitalUse(self, word):
"""
:type word: str
:rtype: bool
"""
n=len(word)
if word[0].isupper():
if n>1:
if word[1].isupper():
for i in word[2:]:
if i.islower():
return False
return True
else:
for i in word[2:]:
if i.isupper():
return False
return True
else:
return True
else:
if n>1:
for i in word[1:]:
if i.isupper():
return False
return True
else:
return True
[LeetCode&Python] Problem 520. Detect Capital的更多相关文章
- 【leetcode】520. Detect Capital
problem 520. Detect Capital 题意: 题目中给出的三种情况,分别是全是大写.全是小写.首字母大写,这三种情况返回True;否则返回False; solution: class ...
- 50. leetcode 520. Detect Capital
520. Detect Capital Given a word, you need to judge whether the usage of capitals in it is right or ...
- Leetcode 520. Detect Capital 发现大写词 (字符串)
Leetcode 520. Detect Capital 发现大写词 (字符串) 题目描述 已知一个单词,你需要给出它是否为"大写词" 我们定义的"大写词"有下 ...
- 520. Detect Capital【easy】
520. Detect Capital[easy] Given a word, you need to judge whether the usage of capitals in it is rig ...
- 【LeetCode】520. Detect Capital 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 循环判断三个条件 大写字母个数和位置判断 根据首字符 ...
- LeetCode 520 Detect Capital 解题报告
题目要求 Given a word, you need to judge whether the usage of capitals in it is right or not. We define ...
- LeetCode - 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...
- LeetCode: 520 Detect Capital(easy)
题目: Given a word, you need to judge whether the usage of capitals in it is right or not. We define t ...
- 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the ...
随机推荐
- png文件格式详解,获取文件的修改时间,创作时间
http://dev.gameres.com/Program/Visual/Other/PNGFormat.htmhttp://www.360doc.com/content/11/0428/12/10 ...
- Javaconfig形式配置Dubbo多注册中心
多注册中心,一般用不到,但是某些情况下的确能解决不少问题,可以将某些dubbo服务注册到2套dubbo系统中,实现服务在2套系统间的共用. 网上的配置说明很多,但包括dubbo官方说明文档都是以xml ...
- 【Jmeter基础知识】Jmeter响应断言和断言结果
一.Jmeter创建一个响应断言 1.步骤:添加--断言--响应断,进入响应断言页面 2.断言内容:可以采用直接去搜索某些文本信息,或者可以去断言某个变量,如图 二.Jmeter创建一个断言结果 1. ...
- 逆袭之旅DAY20.XIA.循环结构
2018-07-16 19:53:47 while循环 do do...while循环 for 循环
- day12-python的类
类的一般形式: 创建类我们一般用class关键字来创建一个类,class后面跟类名字,可以自定义,最后以冒号结尾,如下所示: class ClassName: '''类的说明''' 类的内容 类的内容 ...
- windows下的pycharm配置 linux环境
由于最近学习python的需要,为了方便程序的调试,尝试在Windows下的Pycharm远程连接到虚拟机中Centos下的python环境.(这里我采用的是ssh的远程连接)1.准备工作: 固定ce ...
- Springboot+MyBatis+mysql+jsp页面跳转详细示例
SpringBoot与MyBatis搭建环境,底层数据库为mysql,页面使用JSP(官网上不推荐使用jsp),完成从数据库中查询出数据,在jsp页面中显示,并且实现页面的跳转功能. 项 ...
- 【转载】linux Jumpserver跳板机堡垒机部署安装使用教程
原文地址:https://idc.wanyunshuju.com/li/554.html
- 延迟载入Dll(动态载入Dll)
windows核心编程(第五版)20.3节的延迟载入Dll 延迟载入Dll技术出现的原因: 因为DLL的加载是比较浪费时间的,特别是大型软件加载,因此,这项技术是在应对软件初始化过程中避免浪费太多的时 ...
- Serial interface (RS-232)
转自:http://www.fpga4fun.com/SerialInterface.html A serial interface is a simple way to connect an FPG ...