[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 ...
随机推荐
- MySQL自带功能介绍
前言: 数据库相关的操作 1.SQL语句 *****(MySql(一)已经介绍): 2.利用mysql内部提供的功能(视图.触发器.函数.存储过程: 一.视图: 把经常使用的查询结果,做成临时视图表, ...
- 【转】Vue-详解设置路由导航的两种方法: <router-link :to="..."> 和router.push(...)
一.<router-link :to="..."> to里的值可以是一个字符串路径,或者一个描述地址的对象.例如: // 字符串 <router-link to= ...
- 操作系统IIS安装
IIS在不同的操作系统的安装稍有些差异,如: 1.Windows XP 快捷安装IIS的话,推荐使用IIS一键安装程序包.或者找响应文件包i386,安装所需文件 2.Windows 7 安装IIS,则 ...
- python requests 的cookie 操作
结论: 1.requests模块的请求和响应分别有cookie对象. 可以通过此对象设置和获取cookie. 2.通过在requests.get,requests.post等方法请求中传入cookie ...
- AI新建文件可以新建多个画板5.2
- php把数据转换为json格式
public function demos(){ $data=[ 'state'=>1, 'msg'=>'更新成功' ]; return json_encode($data); }
- Uboot USB模式(RK3288变砖头的解决办法)
RK3288启动后有三种模式,可以分别进行操作. 第一种是normal也就是正常的启动模式.这个模式无法刷固件.一般板子通电就是这个模式 第二种是loader模式.就是刷固件模式.这个模式可以刷各种i ...
- SRAM、DRAM、SDRAM、DDR、DDR2、DDR3
RAM可分为SRAM(Static RAM/静态存储器)和DRAM(Dynamic RAM/动态存储器).SRAM是利用双稳态触发器来保存信息的,只要不掉电,信息是不会丢失的.SRAM存储元件所用MO ...
- Asp.Net WebApi核心对象解析(一)
生活需要自己慢慢去体验和思考,对于知识也是如此.匆匆忙忙的生活,让人不知道自己一天到晚都在干些什么,似乎每天都在忙,但又好似不知道自己到底在忙些什么.不过也无所谓,只要我们知道最后想要什么就行.不管怎 ...
- 学习python二三事儿(二)
多个变量赋值 Python允许你同时为多个变量赋值.例如: a = b = c = 1 以上实例,创建一个整型对象,值为1,三个变量被分配到相同的内存空间上. 您也可以为多个对象指定多个变量.例如: ...