Skip to content

Commit 1ef9d3b

Browse files
authored
Create detect-capital.py
1 parent b2fa911 commit 1ef9d3b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Python/detect-capital.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Time: O(l)
2+
# Space: O(1)
3+
4+
# We define the usage of capitals in a word to be right when one of the following cases holds:
5+
#
6+
# All letters in this word are capitals, like "USA".
7+
# All letters in this word are not capitals, like "leetcode".
8+
# Only the first letter in this word is capital if it has more than one letter, like "Google".
9+
# Otherwise, we define that this word doesn't use capitals in a right way.
10+
# Example 1:
11+
# Input: "USA"
12+
# Output: True
13+
# Example 2:
14+
# Input: "FlaG"
15+
# Output: False
16+
# Note: The input will be a non-empty word consisting of uppercase and lowercase latin letters.
17+
18+
class Solution(object):
19+
def detectCapitalUse(self, word):
20+
"""
21+
:type word: str
22+
:rtype: bool
23+
"""
24+
return word.isupper() or word.islower() or word.istitle()

0 commit comments

Comments
 (0)