力扣(leetcode)第520题检测大写字母(Python)

520.检测大写字母

题目链接:520.检测大写字母

我们定义,在以下情况时,单词的大写用法是正确的:

全部字母都是大写,比如 “USA” 。
单词中所有字母都不是大写,比如 “leetcode” 。
如果单词不只含有一个字母,只有首字母大写, 比如 “Google” 。
给你一个字符串 word 。如果大写用法正确,返回 true ;否则,返回 false 。

示例 1:
输入:word = “USA”
输出:true

示例 2:
输入:word = “FlaG”
输出:false

提示:

1 <= word.length <= 100
word 由小写和大写英文字母组成

解答一

class Solution:
    def detectCapitalUse(self, word: str) -> bool:
        if word.upper()==word:
            return True
        elif word.lower()==word:
            return True
        elif word[1:].lower()==word[1:]:
            return True
        else:
            return False

解答二

class Solution:
    def detectCapitalUse(self, word: str) -> bool:
        return word.lower()==word or word.upper()==word or word.title()==word      

最后,我写了一篇MySQL教程,里面详细的介绍了MySQL的基本概念以及操作指令等内容,欢迎阅读!
MySQL数据库万字保姆级教程

相关推荐

  1. leetcode520检测大写字母Python

    2024-01-11 23:00:01       38 阅读
  2. leetcode383赎金信(Python

    2024-01-11 23:00:01       40 阅读
  3. leetcode482密钥格式化(Python

    2024-01-11 23:00:01       38 阅读
  4. leetcode392判断子序列(Python

    2024-01-11 23:00:01       40 阅读
  5. leetcode796旋转字符串(Python

    2024-01-11 23:00:01       36 阅读
  6. leetcode824山羊拉丁文(Python

    2024-01-11 23:00:01       34 阅读
  7. leetcode66加一(Python

    2024-01-11 23:00:01       35 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-11 23:00:01       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-11 23:00:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-11 23:00:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-11 23:00:01       20 阅读

热门阅读

  1. docker资源控制

    2024-01-11 23:00:01       31 阅读
  2. 2024.1.11

    2024.1.11

    2024-01-11 23:00:01      33 阅读
  3. 基于uniapp 组件uniform 得自定义picker 选择器

    2024-01-11 23:00:01       27 阅读
  4. Sqlite3相关返回值

    2024-01-11 23:00:01       28 阅读
  5. springboot 集成kafka

    2024-01-11 23:00:01       37 阅读
  6. springboot常见注解

    2024-01-11 23:00:01       37 阅读
  7. GO语言Context的作用

    2024-01-11 23:00:01       29 阅读
  8. 回溯算法part01 算法

    2024-01-11 23:00:01       35 阅读
  9. C++中ios::in, ios::out, ios::trunc使用

    2024-01-11 23:00:01       37 阅读