当前位置:网站首页>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
};
边栏推荐
- Leetcode19. Delete the penultimate node of the linked list [double pointer]
- [record of question brushing] 3 Longest substring without duplicate characters
- 今日创见|企业促进创新的5大关键要素
- DTC社群运营怎么做?
- Unity与WebGL的相爱相杀
- Installing vmtools is gray
- 网络安全-钓鱼
- Unity 动态合并网格纹理
- Line test - graphic reasoning -5- one stroke class
- 【刷题记录】3. 无重复字符的最长子串
猜你喜欢
Comparison of various development methods of applets - cross end? Low code? Native? Or cloud development?
DTC社群运营怎么做?
Line test graph reasoning graph group class
Line measurement - graphic reasoning -9- line problem class
Basic knowledge of linked list
Two minutes, talk about some wrong understandings of MySQL index
Line test - graphic reasoning -7- different graphic classes
面试百问:如何测试App性能?
[record of question brushing] 3 Longest substring without duplicate characters
CTF exercise
随机推荐
Basic knowledge of linked list
OC variable parameter transfer
The author of LinkedList said he didn't use LinkedList himself
GBU1510-ASEMI电源专用15A整流桥GBU1510
Years of summary, some core suggestions for learning programming
Line test - graphic reasoning - 1 - Chinese character class
Cases of agile innovation and transformation of consumer goods enterprises
Brush question 5
Debezium series: MySQL tombstone event
Early childhood education industry of "screwing bar": trillion market, difficult to be a giant
Develop those things: go plus c.free to free memory, and what are the reasons for compilation errors?
微信论坛交流小程序系统毕业设计毕设(3)后台功能
Txt file virus
Sword finger offer 27 Image of binary tree
./ setup. Insufficient sh permission
Two minutes, talk about some wrong understandings of MySQL index
2021-01-11
Sword finger offer 63 Maximum profit of stock
Software evaluation center ▏ what are the basic processes and precautions for automated testing?
Exploratory data analysis of heartbeat signal