File tree 3 files changed +37
-1
lines changed
3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 137
137
| 506 | [ Relative Ranks] ( https://leetcode.com/problems/relative-ranks ) | Easy | [ ![ Java] ( assets/java.png )] ( src/RelativeRanks.java ) [ ![ Python] ( assets/python.png )] ( python/relative_ranks.py ) |
138
138
| 507 | [ Perfect Number] ( https://leetcode.com/problems/perfect-number ) | Easy | [ ![ Java] ( assets/java.png )] ( src/CheckPerfectNumber.java ) [ ![ Python] ( assets/python.png )] ( python/check_perfect_number.py ) |
139
139
| 509 | [ Fibonacci Number] ( https://leetcode.com/problems/fibonacci-number ) | Easy | [ ![ Java] ( assets/java.png )] ( src/FibonacciNumber.java ) [ ![ Python] ( assets/python.png )] ( python/fibonacci_number.py ) |
140
- | 520 | [ Detect Capital] ( https://leetcode.com/problems/detect-capital ) | Easy | |
140
+ | 520 | [ Detect Capital] ( https://leetcode.com/problems/detect-capital ) | Easy | [ ![ Java ] ( assets/java.png )] ( src/DetectCapital.java ) [ ![ Python ] ( assets/python.png )] ( python/detect_capital.py ) |
141
141
| 521 | [ Longest Uncommon Subsequence I] ( https://leetcode.com/problems/longest-uncommon-subsequence-i ) | Easy | |
142
142
| 530 | [ Minimum Absolute Difference in BST] ( https://leetcode.com/problems/minimum-absolute-difference-in-bst ) | Easy | |
143
143
| 532 | [ K - Diff Pairs in Array] ( https://leetcode.com/problems/k-diff-pairs-in-an-array ) | Easy | |
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def detectCapitalUse (self , word : str ) -> bool :
3
+ return word .isupper () or word .islower () or word [0 ].isupper () and self .isLower (word , 1 )
4
+
5
+ def isLower (self , word : str , start : int ) -> bool :
6
+ for index in range (start , len (word )):
7
+ if word [index ].isupper ():
8
+ return False
9
+ return True
Original file line number Diff line number Diff line change
1
+ public class DetectCapital {
2
+ public boolean detectCapitalUse (String word ) {
3
+ return isAllCaps (word ) || isAllLowerCase (word , 0 ) || firstCharIsCapital (word );
4
+ }
5
+
6
+ private boolean isAllCaps (String string ) {
7
+ for (int index = 0 ; index < string .length () ; index ++) {
8
+ if (Character .isLowerCase (string .charAt (index ))) {
9
+ return false ;
10
+ }
11
+ }
12
+ return true ;
13
+ }
14
+
15
+ private boolean isAllLowerCase (String string , int start ) {
16
+ for (int index = start ; index < string .length () ; index ++) {
17
+ if (Character .isUpperCase (string .charAt (index ))) {
18
+ return false ;
19
+ }
20
+ }
21
+ return true ;
22
+ }
23
+
24
+ private boolean firstCharIsCapital (String string ) {
25
+ return Character .isUpperCase (string .charAt (0 )) && isAllLowerCase (string , 1 );
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments