반응형
Write a function that will check if two given characters are the same case.
- If either of the characters is not a letter, return -1
- If both characters are the same case, return 1
- If both characters are letters, but not the same case, return 0
Examples
'a' and 'g' returns 1
'A' and 'C' returns 1
'b' and 'G' returns 0
'B' and 'g' returns 0
'0' and '?' returns -1
Solution:
def same_case(a: str, b: str) -> int:
return int(a.isupper() == b.isupper()) if a.isalpha() and b.isalpha() else -1
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0125. Counting sheep... (0) | 2023.01.25 |
---|---|
0124. Regular Ball Super Ball (0) | 2023.01.24 |
0122. The Feast of Many Beasts (0) | 2023.01.23 |
0121. esreveR (0) | 2023.01.21 |
0120. Alphabet symmetry (0) | 2023.01.21 |