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
[暴力解法]:
时间分析:
空间分析:
[优化后]:
时间分析:
空间分析:
[奇葩输出条件]:
[奇葩corner case]:
[思维问题]:
不知道怎么表示大写字母:c <= 'Z'
[一句话思路]:
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分钟肉眼debug的结果]:
[总结]:
c <= 'Z'
[复杂度]:Time complexity: O(n) Space complexity: O(1)
[英文数据结构或算法,为什么不用别的数据结构或算法]:
charAt 可以把字符串中的字母单独抽出来
[关键模板化代码]:
统计大写字母:
for (char c : word.toCharArray()) {
if (c <= 'Z') count++;
}
[其他解法]:
[Follow Up]:
[LC给出的题目变变变]:
[代码风格] :
class Solution {
public boolean detectCapitalUse(String word) {
//ini
int count = 0;
for (char c : word.toCharArray()) {
if (c <= 'Z') count++;
}
if (count == 0 || count == word.length() || (count == 1 && word.charAt(0) <= 'Z')) {
return true;
}
return false;
}
}
520. Detect Capital判断单词有效性的更多相关文章
- Leetcode 520. Detect Capital 发现大写词 (字符串)
Leetcode 520. Detect Capital 发现大写词 (字符串) 题目描述 已知一个单词,你需要给出它是否为"大写词" 我们定义的"大写词"有下 ...
- 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 ...
- 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
problem 520. Detect Capital 题意: 题目中给出的三种情况,分别是全是大写.全是小写.首字母大写,这三种情况返回True;否则返回False; solution: class ...
- 520 Detect Capital 检测大写字母
给定一个单词,你需要判断单词的大写使用是否正确.我们定义,在以下情况时,单词的大写用法是正确的: 全部字母都是大写,比如"USA". 单词中所有字母都不是大写,比如&q ...
- 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the ...
- 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(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 u ...
随机推荐
- 使用 minio 搭建私有对象存储云。aws-php-sdk 操作object
How to use AWS SDK for PHP with Minio Server aws-sdk-php is the official AWS SDK for the PHP program ...
- Java各种集合容器的总结
Java容器指的是List,Set,Map这些类.由于翻译的问题,问到集合,Collection这些指的都是它们几个. List ArrayList 随机访问快 LinkedList 插入删除快 这个 ...
- FastAdmin 2018-05-26 更新时更新了 SQL 文件 关于 ROW_FORMAT=DYNAMIC 改为 ROW_FORMAT=COMPACT 问题
FastAdmin 2018-05-26 更新时更新了 SQL 文件 关于 ROW_FORMAT=DYNAMIC 改为 ROW_FORMAT=COMPACT 问题 观查到 FastAdmin 在 20 ...
- (转)Android代码混淆-添加了Gson遇到的问题
折腾了好久.....郁闷 -_- 1.首先,project.properties里的配置文件变了,之前的项目一直都是在project.properties这个文件中添加一行proguard.confi ...
- (转)RadioButton左侧显示文字,右侧显示按钮时文字不靠边的问题解决
作者: 发布日期:2014-02-13 21:00:45 我来说两句(0) 0 Tag标签:RadioButton 左侧 显示 项目中有一个这样的需求: 下面三行点击某行即选中,颜色变深.自 ...
- 如何设计并使用FireMonkeyStyle
如何设计并使用FireMonkeyStyle FireMonkey使用Style来控制控件的显示方式. 每个控件都有一个StyleLookup属性,FireMonkey就是通过控件的这个属性来在当前窗 ...
- mysql concat的使用
想要在一个id前都加个0,如果处理呢? mysql concat的使用 update `a_data` set id=CONCAT('0', id) where data_packet_id in ( ...
- GOF23设计模式之工厂模式(factory)
一.工厂模式概述 实现了创建者和调用者的分离 (1)分类 ①简单工厂模式 虽然某种程度不符合设计原则,但实际使用最多. ②工厂方法模式 不修改已有类的前提下,通过增加新的工厂类实现扩展. ③抽象工厂模 ...
- Object-C 多线程中锁的使用-NSLock
在多线程的编程环境中,锁的使用必不可少! 于是,今天来总结一下为共享资源加锁的操作方法. 一.使用synchronized方式 //线程1 dispatch_async(dispatch_ge ...
- 终端启动tomcat报错 command not found 解决方法 (含启动和关闭命令)
Tomcat配置步骤: 1.cd命令进入Tomcat安装路径的bin下 2.sudo chmod 755*.sh 输入appleID密码获得相关权限 3.sudo sh ./startup.sh启动T ...