C++题解-Leecode 520. 检测大写字母——Leecode每日一题系列
生活随笔
收集整理的這篇文章主要介紹了
C++题解-Leecode 520. 检测大写字母——Leecode每日一题系列
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天是堅持每日一題打卡的第十八天
題目鏈接:https://leetcode-cn.com/problems/detect-capital/
題解匯總:https://zhanglong.blog.csdn.net/article/details/121071779
題目描述
我們定義,在以下情況時,單詞的大寫用法是正確的:
全部字母都是大寫,比如 “USA” 。
單詞中所有字母都不是大寫,比如 “leetcode” 。
如果單詞不只含有一個字母,只有首字母大寫, 比如 “Google” 。
給你一個字符串 word 。如果大寫用法正確,返回 true ;否則,返回 false 。
示例 1:
輸入:word = “USA”
輸出:true
示例 2:
輸入:word = “FlaG”
輸出:false
提示:
1 <= word.length <= 100
word 由小寫和大寫英文字母組成
簡單模擬,注意代碼的簡潔和美觀
class Solution { public:bool detectCapitalUse(string word) {string temp;for (auto i : word) {temp += toupper(i);}if(word == temp) return true;temp = "";for(auto i : word) {temp += tolower(i);}if(word == temp) return true;temp[0] = toupper(temp[0]);if(word == temp) return true;return false;} };總結
以上是生活随笔為你收集整理的C++题解-Leecode 520. 检测大写字母——Leecode每日一题系列的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++题解-Leecode 375. 猜
- 下一篇: 数字签名、数字证书、对称加密算法、非对称