当前位置:网站首页>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;
}
};
边栏推荐
- 等保备案是什么意思?应该去哪里办理备案?
- MySQL | view notes on Master Kong MySQL from introduction to advanced
- Picture tools
- input的聚焦后的边框问题
- 所说的Get post:请求的区别,你真的知道了吗??????
- [team management] 25 tips for testing team performance management
- IDEA另起一行快捷键
- String to Base64
- What is SRE? A detailed explanation of SRE operation and maintenance system
- Get screen width and height tool class
猜你喜欢

Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system

从华为WeAutomate数字机器人论坛,看政企领域的“政务新智理”

【E325: ATTENTION】vim编辑时报错

opencv最大值滤波(不局限于图像)

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

Become an IEEE student member

A tip to read on Medium for free

玄铁E906移植----番外0:玄铁C906仿真环境搭建

【LeetCode】415. 字符串相加

数据中台:中台架构及概述
随机推荐
Telnet port login method with user name for liunx server
Using ngrok for intranet penetration
liunx服务器 telnet 带用户名 端口登陆方法
数组相向指针系列
110. balanced binary tree recursive method
What is SRE? A detailed explanation of SRE operation and maintenance system
开源之夏中选名单已公示,基础软件领域成为今年的热门申请
数据库迁移从PostgreSQL迁移到 MYSQL
DataX User Guide
1704. 判断字符串的两半是否相似
【NOI模拟赛】摆(线性代数,杜教筛)
[force deduction 10 days SQL introduction] Day3
It is enough to read this article about ETL. Three minutes will let you understand what ETL is
【LeetCode】387. 字符串中的第一个唯一字符
Sword finger offer 55 - I. depth DFS method of binary tree
input的聚焦后的边框问题
[team management] 25 tips for testing team performance management
2138. 将字符串拆分为若干长度为 k 的组
Jenkins自动化部署,连接不到所依赖的服务【已解决】
数据中台:数据中台全栈技术架构解析,附带行业解决方案