[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 ...
随机推荐
- python操作文件(增、删、改、查)
内容 global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 local2 info defaults log global mode ...
- this.$route和this.$router的区别
1. this.$router: 表示全局路由器对象,项目中通过router路由参数注入路由之后,在任何一个页面都可以通过此方法获取到路由器对象,并调用其push(), go()等方法: 2. thi ...
- IDE 版本
BDS 5 2007 D11 VER180 and VER185 RAD Studio 8 XE D15 VER 220 RAD 18 XE 10.1 Berlin D24 VER310 St ...
- 软件设计基础-C/S系统
在软件设计开发过程中,逐渐形成了一些针对特定应用领域的软件系统组织方式的惯用模式 如经典的C/S(client/server,客户/服务器)模式和B/S(browser/server,浏览器/服务器) ...
- 一. Python基础(1)--语法
一. Python基础(1)--语法 1. 应用程序 1.1 什么是计算机(Computer)? 组成 ①运算器 arithmetic unit; ※ Arithmetic unit and cont ...
- 1.2socket服务器使用多线程
socket服务器代码如下 # -*- coding: utf-8 -*-from socket import * import time import threading,_thread as th ...
- bootstrap 下拉选中查询
<div class="form-group"> <label class="col-lg-3 col-sm-2 control-label" ...
- angular自定义指令
1.在directive文件下创建指令的js文件 通常自定义指令需要声明模块(注意定义指令时, js内部指令名称需采用 aaAaBb驼峰的命名方式 html中使用的是aa-aa-bb) e.g (f ...
- 关于MEX函数的说明
reference:http://www.mathworks.com/help/matlab/ref/mex.html .MEX文件是一种可在matlab环境中调用的C(或fortran)语言衍生程序 ...
- L1-056 猜数字
一群人坐在一起,每人猜一个 100 以内的数,谁的数字最接近大家平均数的一半就赢.本题就要求你找出其中的赢家. 输入格式: 输入在第一行给出一个正整数N(≤104).随后 N 行,每行给出一个玩 ...