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 ...
随机推荐
- linux基础【文件夹含义】
linux文件目录是一个树状的目录 bin -->可执行文件 boot-->操作系统引导文件,系统内核,启动信息 dev -->device,设备信息,计算机硬件设备信息 etc - ...
- 21天学通C++_Day3_Part1
今天奔跑吧兄弟来杭电了,决定不去看,宅在科协继续啃(反正去了也看不到咯),继续继续,今天白天没课,希望可以更两个. 0.C风格字符串 在数组中间把某个字符替换成‘\0’并不会改变数组的长度,但是显示时 ...
- Activiti工作流学习之流程图应用详解
Activiti工作流学习之流程图应用详解 1.目的 了解Activiti工作流是怎样应用流程图的. 2.环境准备2.1.相关软件及版本 jdk版本:Jdk1.7及以上 IDE:eclipse ...
- python的一些开源库
SQLAlchemy——数据持久层框架 简介 SQLAlchemy 主要由两部分组成,一个 SQL 工具包和一个关系对象映射(ORM),它能让开发者完全发挥出 SQL 的灵活性与强大的能量.他实现了一 ...
- log4j及其log4j2的使用
简单的说 log4j2 是log4j2的升级版,据说采用了一些新技术(无锁异步.等等),使得日志的吞吐量.性能比log4j 1.x提高10倍,并解决了一些死锁的bug,而且配置更加简单灵活.其使用方式 ...
- FPGA前世今生(二)
上期我们介绍了关于FPGA内部最基本的结构,在quartus下可以看到整体的结构. 这是在平面规划图下看到的结构,其中蓝色的小格代表一个LAB.四周边上浅棕色的小格代表IO口. 这是一个LAB的内部结 ...
- AIX PowerHA (HACMP) Commands
PowerHA(HACMP) Commands How to start cluster daemons (options in that order: clstrmgr, clsmuxpd, br ...
- classpath和环境变量设置
一.简介: 环境变量是操作系统.应用程序.脚本程序等等的指明灯,能够告诉他们需要的资源在哪里.大多数的 系统都有一些预先设置好的环境变量,当然,我们也可以增加自己的环境变量. 为了看看当前系统的环境变 ...
- 移植LWIP(ENC28J60)
上图就是整个移植的基本思路,非常清晰的三个层次.其实想想,本质上就是收发数据,只是LWIP协议通过对数据的封装可以实现网络传输.从图中我们就可以看到这里首先需要ENC28J60的驱动,这个驱动需 ...
- java中绘图-----那个鼠标等的监听我还是不太会,,好苦恼啊。不知道这些监听事件是怎么区分的
总结::监听到底该怎么用 事件的区分是靠判断还是 package com.a.b; //我想实现,当我点击一个按钮时,这个frame里可以画出实心的矩形 import java.awt.Color; ...