当前位置:网站首页>520. detect capital letters
520. detect capital letters
2022-06-24 08:52:00 【Drag is me】
leetcode Force button to brush questions and punch in
subject :520. Detect capital letters
describe : We define , When , The capitalization of words is correct :
All the letters are uppercase , such as “USA” .
All the letters in a word are not capitalized , such as “leetcode” .
If a word contains more than one letter , Only the first letter is capitalized , such as “Google” .
Give you a string word . If capitalized correctly , return true ; otherwise , return false .
Their thinking
1、 Sequential programming ;
2、 First determine whether the first letter is upper case or lower case , If word[0] It's lowercase , Then the following must be lowercase to return true;
3、 If word[0] It's capital , There are two situations , see word[1] Uppercase or lowercase . If word[1] It's capital , The following must also be capitalized to return true; If word[1] It's lowercase , The following must all be lowercase to return true;
Source code ##
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;
}
};
边栏推荐
- PHP code encryption + extended decryption practice
- Get screen width and height tool class
- 【牛客】HJ1 字符串最后一个单词的长度
- Idea another line shortcut
- Detailed explanation of Base64 coding and its variants (to solve the problem that the plus sign changes into a space in the URL)
- 第七章 操作位和位串(三)
- 小程序云数据,数据请求一个集合数据的方法
- 偶然间得到的framework工具类 自用
- 2020中国全国各省市,三级联动数据,数据机构(数据来自国家统计局官网)
- 【E325: ATTENTION】vim编辑时报错
猜你喜欢

WebRTC系列-网络传输之5选择最优connection切换

Matlab camera calibrator camera calibration

基于QingCloud的 “房地一体” 云解决方案

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

数据库迁移从PostgreSQL迁移到 MYSQL
![[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle](/img/db/e581087e550a2e460f12047685c48f.png)
[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle

JS to find and update the specified value in the object through the key

Jenkins自动化部署,连接不到所依赖的服务【已解决】

MySQL | 视图《康师傅MySQL从入门到高级》笔记

从华为WeAutomate数字机器人论坛,看政企领域的“政务新智理”
随机推荐
不能改变虚拟机电源状态报错解决方案
【E325: ATTENTION】vim编辑时报错
Analyze the meaning of Internet advertising terms CPM, CPC, CPA, CPS, CPL and CPR
【NOI模拟赛】给国与时光鸡(构造)
What is the future development trend of Business Intelligence BI
Fast and slow pointer series
mysql写的代码数据 增删查改等等
基于QingCloud的地理信息企业研发云解决方案
开源之夏中选名单已公示,基础软件领域成为今年的热门申请
[team management] 25 tips for testing team performance management
所说的Get post:请求的区别,你真的知道了吗??????
Idea another line shortcut
2022春招面试总结
【MySQL从入门到精通】【高级篇】(一)字符集的修改与底层原理
MySQL | store notes of Master Kong MySQL from introduction to advanced
[10 day SQL introduction] Day2
[force deduction 10 days SQL introduction] Day3
4275. Dijkstra序列
用VNC Viewer的方式远程连接无需显示屏的树莓派
Detailed explanation of Base64 coding and its variants (to solve the problem that the plus sign changes into a space in the URL)