当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢
![[team management] 25 tips for testing team performance management](/img/bd/0ef55630de43efcf5aa663f3099fce.jpg)
[team management] 25 tips for testing team performance management

KaFormer个人笔记整理

What is the future development trend of Business Intelligence BI

【E325: ATTENTION】vim编辑时报错
![打印出来的对象是[object object],解决方法](/img/fc/9199e26b827a1c6304fcd250f2301e.png)
打印出来的对象是[object object],解决方法

110. balanced binary tree recursive method

疫情、失业,2022,我们高喊着摆烂和躺平!

原生小程序用画布制作海报,等比例缩放,和uniapp差不多就是写法有点不同

4274. 后缀表达式
![[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
随机推荐
什么是图神经网络?图神经网络有什么用?
1528. 重新排列字符串
数据中台:数据采集和抽取的技术栈详解
110. balanced binary tree recursive method
小程序云数据,数据请求一个集合数据的方法
第七章 操作位和位串(三)
Analyze the meaning of Internet advertising terms CPM, CPC, CPA, CPS, CPL and CPR
Change SSH port number
String to Base64
mysql写的代码数据 增删查改等等
The form image uploaded in chorme cannot view the binary image information of the request body
【量化投资】离散傅里叶变换求数组周期
GradScaler MaxClipGradScaler
Array opposite pointer series
Prompt code when MySQL inserts Chinese data due to character set problems: 1366
【LeetCode】541. 反转字符串 II
2022 spring recruitment interview summary
Jenkins自动化部署,连接不到所依赖的服务【已解决】
Fast and slow pointer series
rpiplay实现树莓派AirPlay投屏器