Leetcode 520 Detect Capital
来源:互联网 发布:网络上的聊污什么意思 编辑:程序博客网 时间:2024/05/29 00:33
Leetcode 520 Detect Capital
#include <string>using namespace std;class Solution {public: bool detectCapitalUse(string word) { if (word.length() <= 1) return true; bool sign = true; if (isupper(word[0])){ int upperCount = 0; for (int i = 1; i < word.length(); i++){ if (isupper(word[i])) upperCount++; } if (upperCount != 0 && upperCount != word.length() - 1) sign = false; } else if (islower(word[0])){ for (int i = 0; i < word.length(); i++){ if (isupper(word[i])) sign = false; } } return sign; }};class Solution {public: bool detectCapitalUse(string word) { int upperCount =0; //变量一定要初始化 for (int i = 0; i < word.length(); i++){ if (word[i] >= 'A' && word[i] <= 'Z') upperCount++; } if (word[0] >= 'A' && word[0] <= 'Z'){ if (upperCount == 1 || upperCount == word.length()) return true; } else if (upperCount == 0) return true; return false; }};//这样比上一种方法要快一倍
阅读全文
0 0
- leetcode-520-Detect Capital
- Leetcode #520 Detect Capital
- [LeetCode]520 Detect Capital
- LeetCode 520:Detect Capital
- LeetCode 520 Detect Capital
- Leetcode 520 Detect Capital
- LeetCode 520 Detect Capital
- 【LeetCode】520 Detect Capital
- Leetcode 520 Detect Capital
- LeetCode.520 Detect Capital
- leetcode 520 Detect Capital C++
- leetcode 520[easy]---Detect Capital
- LeetCode 520:Detect Capital (c++)
- LeetCode 520 Detect Capital 检测大写
- 【Leetcode】520. Detect Capital
- LeetCode 520. Detect Capital
- LeetCode 520. Detect Capital
- LeetCode:Detect Capital
- Eclipse使用设置(持续更新中)
- Eclipse常用快捷键
- POJ 2507 Crossed ladders 笔记
- linux hosts的allow和deny
- ssh_exchange_identification: Connection closed by remote hos
- Leetcode 520 Detect Capital
- 找出数组中重复的数字
- 原生javascript写的无缝滚动轮播图
- Java记录 -42- Java Collection
- Java记录 -43- Java ArrayList
- Java记录 -44- Object数组陷阱
- lua 与c#交互原理
- Java记录 -45- List的toString方法
- 认识ZooKeeper