当前位置:网站首页>leetcode-520. 检测大写字母-js
leetcode-520. 检测大写字母-js
2022-07-07 21:50:00 【前端千帆】
题目
代码
/** * @param {string} word * @return {boolean} */
var detectCapitalUse = function(word) {
// 只有一个字母,不管大小写都返回 true
if (word.length === 1) return true
const upperStr = word.toUpperCase()
const lowerStr = word.toLowerCase()
if (word === upperStr || word === lowerStr) {
// 当全部字母都是大写或者小写时
return true;
} else if (word[0] <= 'Z' && word[0] >= 'A' && word.slice(1) === lowerStr.slice(1)) {
// 当首字母是大写,其他字母都是小写时
return true
}
return false
};
边栏推荐
- One question per day - pat grade B 1002 questions
- 微生物健康網,如何恢複微生物群落
- 微信论坛交流小程序系统毕业设计毕设(3)后台功能
- 【测试面试题】页面很卡的原因分析及解决方案
- Class implementation of linear stack and linear queue (another binary tree pointer version)
- U盘拷贝东西时,报错卷错误,请运行chkdsk
- 网络安全-安装CentOS
- QT graphicsview graphical view usage summary with flow chart development case prototype
- Brush question 5
- Database daily question --- day 22: last login
猜你喜欢
Line test - graphic reasoning - 1 - Chinese character class
Microbial health network, how to restore microbial communities
Line test - graphic reasoning - 6 - similar graphic classes
行测-图形推理-5-一笔画类
Cases of agile innovation and transformation of consumer goods enterprises
Anta DTC | Anta transformation, building a growth flywheel that is not only FILA
LeetCode206. Reverse linked list [double pointer and recursion]
Ligne - raisonnement graphique - 4 - classe de lettres
[record of question brushing] 3 Longest substring without duplicate characters
微信论坛交流小程序系统毕业设计毕设(5)任务书
随机推荐
Line test - graphic reasoning - 1 - Chinese character class
Why is network i/o blocked?
Line test - graphic reasoning -7- different graphic classes
网络安全-永恒之蓝
Installing vmtools is gray
PCL . VTK files and Mutual conversion of PCD
小程序多种开发方式对比-跨端?低代码?原生?还是云开发?
Leetcode94. Middle order traversal of binary trees
Line test - graphic reasoning - 2 - black and white lattice class
【测试面试题】页面很卡的原因分析及解决方案
定位到最底部[通俗易懂]
Software test classification
Circumvention Technology: Registry
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades-KDD2020
Guessing game (read data from file)
LeetCode144. Preorder traversal of binary tree
Line test graph reasoning graph group class
Debezium series: binlogreader for source code reading
Debezium系列之:支持 mysql8 的 set role 語句
【刷题记录】3. 无重复字符的最长子串