https://leetcode.com/problems/detect-capital/
class Solution:
def detectCapitalUse(self, word: str) -> bool:
return word in [word.upper(), word.lower(), word.capitalize()]
한 줄 컷 멋지다!
내장함수 날먹이 싫은 사람을 위한 별해
class Solution:
def detectCapitalUse(self, word: str) -> bool:
return sum([i+1 for i,w in enumerate(word) if ord(w)<=ord('Z')]) in [0,1,len(word)*(len(word)+1)//2]
댓글 0