当前位置:网站首页>520. 检测大写字母
520. 检测大写字母
2022-06-24 07:06:00 【拽拽就是我】
leetcode力扣刷题打卡
题目:520. 检测大写字母
描述:我们定义,在以下情况时,单词的大写用法是正确的:
全部字母都是大写,比如 “USA” 。
单词中所有字母都不是大写,比如 “leetcode” 。
如果单词不只含有一个字母,只有首字母大写, 比如 “Google” 。
给你一个字符串 word 。如果大写用法正确,返回 true ;否则,返回 false 。
解题思路
1、顺序编程;
2、先判断第一个字母是大写还是小写,如果word[0]是小写,那么后面的必须都小写才能返回true;
3、如果word[0]是大写,还要分两种情况,看word[1]是大写还是小写。如果word[1]是大写,后面的必须也都是大写才返回true;如果word[1]是小写,后面也必须都是小写才返回true;
原代码##
class Solution {
public:
bool detectCapitalUse(string word) {
int len = word.size();
if (len == 1) return true;
if (word[0] >= 'a' && word[0] <= 'z') {
for (int i = 1; i < word.size(); ++i) {
if (word[i] >= 'A' && word[i] <= 'Z') return false;
}
return true;
} else {
if (word[1] >= 'A' && word[1] <= 'Z') {
for (int i = 1; i < word.size(); ++i) {
if (word[i] >= 'a' && word[i] <= 'z') return false;
}
return true;
} else {
for (int i = 1; i < word.size(); ++i) {
if (word[i] >= 'A' && word[i] <= 'Z') return false;
}
return true;
}
}
return true;
}
};
边栏推荐
- Xiaohei ai4code code baseline nibble 1
- (pkcs1) RSA public private key PEM file parsing
- DataX User Guide
- RuntimeError: Missing dependencies:XXX
- QT source code analysis -- QObject (2)
- MySQL 因字符集问题插入中文数据时提示代码 :1366
- 5 minutes, excellent customer service chat handling skills
- Common misconceptions in Tencent conference API - signature error_ code 200003
- 【力扣10天SQL入门】Day2
- 更改SSH端口号
猜你喜欢

MySQL 因字符集问题插入中文数据时提示代码 :1366

js中通过key查找和更新对象中指定值的方法

2022.06.23(LC_144,94,145_二叉树的前序、中序、后序遍历)

À propos de ETL il suffit de lire cet article, trois minutes pour vous faire comprendre ce qu'est ETL

Qt 中发送自定义事件

教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5
![[untitled]](/img/94/792e8363dbfe67770e93b0dcdc8e72.png)
[untitled]

liunx服务器 telnet 带用户名 端口登陆方法

Vscode install the remote -wsl plug-in to connect to the local WSL

【NOI模拟赛】寄(树形DP)
随机推荐
Background management of uniapp hot update
Live broadcast appointment: growth of Mengxin Product Manager
Two methods of QT exporting PDF files
WebRTC系列-网络传输之5选择最优connection切换
[untitled]
There was an error checking the latest version of pip
rpiplay实现树莓派AirPlay投屏器
Three ways to uninstall Symantec Endpoint Protection Symantec
input的聚焦后的边框问题
pymysql 向MySQL 插入数据无故报错
【NOI模拟赛】寄(树形DP)
Glusterfs replacement failure brick
小黑ai4code代码baseline啃食1
Easynvr and easyrtc platforms use go language to manage projects. Summary of the use of govendor and gomod
PHP代码加密的几种方案
Qt 中发送自定义事件
liunx服务器 telnet 带用户名 端口登陆方法
The pie chart with dimension lines can set various parameter options
Vscode install the remote -wsl plug-in to connect to the local WSL
orb slam build bug: undefined reference to symbol ‘_ ZN5boost6system15system_ categoryEv‘