
Problem
Solution
Analysis
Python implementation
1 2 3 4 5 6 7
|
class : def detectCapitalUse(self, word): """ :type word: str :rtype: bool """ return word == word.lower() or word == word.upper() or word == word.capitalize()
|
Java implementation
1 2 3 4 5
|
class { public boolean detectCapitalUse(String word) { return (word.equals(word.toLowerCase())) || (word.equals(word.toUpperCase())) || (word.equals(Character.toUpperCase(word.charAt(0))+word.substring(1).toLowerCase())); } }
|
Time complexity
O(n).
Space complexity
O(n).
Links
520. Detect Capital
(中文版) 算法笔记: 力扣#520 检测大写字母
近期评论