""" 0520.1 - Solution 1 - Built-in String Methods """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def detectCapitalUse(self, word: str) -> bool:
"""Detect Capital Use Function"""
return word.isupper() or word.islower() or word.istitle()
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().detectCapitalUse("USA")) # True
print(Solution().detectCapitalUse("leetcode")) # True
print(Solution().detectCapitalUse("Google")) # True
print(Solution().detectCapitalUse("FlaG")) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0520.2 - Solution 2 - Count Uppercase Letters """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def detectCapitalUse(self, word: str) -> bool:
"""Detect Capital Use Function"""
upper_count = sum(1 for c in word if c.isupper())
return upper_count == 0 or upper_count == len(word) or (upper_count == 1 and word[0].isupper())
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().detectCapitalUse("USA")) # True
print(Solution().detectCapitalUse("leetcode")) # True
print(Solution().detectCapitalUse("Google")) # True
print(Solution().detectCapitalUse("FlaG")) # False
print(Solution().detectCapitalUse("gooGle")) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()